kiosk printing (#1034)
This commit is contained in:
@@ -67,7 +67,7 @@ from skyvern.webeye.actions.actions import (
|
|||||||
WebAction,
|
WebAction,
|
||||||
)
|
)
|
||||||
from skyvern.webeye.actions.responses import ActionAbort, ActionFailure, ActionResult, ActionSuccess
|
from skyvern.webeye.actions.responses import ActionAbort, ActionFailure, ActionResult, ActionSuccess
|
||||||
from skyvern.webeye.browser_factory import BrowserState, get_download_dir
|
from skyvern.webeye.browser_factory import BrowserState
|
||||||
from skyvern.webeye.scraper.scraper import (
|
from skyvern.webeye.scraper.scraper import (
|
||||||
CleanupElementTreeFunc,
|
CleanupElementTreeFunc,
|
||||||
ElementTreeFormat,
|
ElementTreeFormat,
|
||||||
@@ -386,19 +386,7 @@ async def handle_click_to_download_file_action(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await locator.click(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
|
await locator.click(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
|
||||||
|
|
||||||
await page.wait_for_load_state(timeout=SettingsManager.get_settings().BROWSER_LOADING_TIMEOUT_MS)
|
await page.wait_for_load_state(timeout=SettingsManager.get_settings().BROWSER_LOADING_TIMEOUT_MS)
|
||||||
# TODO: shall we back to the previous page ?
|
|
||||||
if await SkyvernFrame.get_print_triggered(page):
|
|
||||||
path = f"{get_download_dir(task.workflow_run_id, task.task_id)}/{uuid.uuid4()}"
|
|
||||||
LOG.warning(
|
|
||||||
"Trying to download the printed PDF",
|
|
||||||
path=path,
|
|
||||||
action=action,
|
|
||||||
)
|
|
||||||
await page.pdf(format="A4", display_header_footer=True, path=path)
|
|
||||||
await SkyvernFrame.reset_print_triggered(page)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception("ClickAction with download failed", action=action, exc_info=True)
|
LOG.exception("ClickAction with download failed", action=action, exc_info=True)
|
||||||
return [ActionFailure(e, download_triggered=False)]
|
return [ActionFailure(e, download_triggered=False)]
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class BrowserContextFactory:
|
|||||||
"--disable-blink-features=AutomationControlled",
|
"--disable-blink-features=AutomationControlled",
|
||||||
"--disk-cache-size=1",
|
"--disk-cache-size=1",
|
||||||
"--start-maximized",
|
"--start-maximized",
|
||||||
|
"--kiosk-printing",
|
||||||
],
|
],
|
||||||
"ignore_default_args": [
|
"ignore_default_args": [
|
||||||
"--enable-automation",
|
"--enable-automation",
|
||||||
|
|||||||
@@ -28,16 +28,6 @@ def load_js_script() -> str:
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
DISABLE_PRINTER_WITH_FLAG = """
|
|
||||||
(function() {
|
|
||||||
const originalPrint = window.print;
|
|
||||||
window.print = function() {
|
|
||||||
window.__printTriggered = true;
|
|
||||||
};
|
|
||||||
window.__printTriggered = false;
|
|
||||||
})();
|
|
||||||
"""
|
|
||||||
|
|
||||||
JS_FUNCTION_DEFS = load_js_script()
|
JS_FUNCTION_DEFS = load_js_script()
|
||||||
|
|
||||||
|
|
||||||
@@ -128,22 +118,6 @@ class SkyvernFrame:
|
|||||||
|
|
||||||
return screenshots
|
return screenshots
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
async def get_print_triggered(page: Page) -> bool:
|
|
||||||
"""
|
|
||||||
Get print triggered on the page. Only Page instance could be printed as PDF.
|
|
||||||
"""
|
|
||||||
# the flag was injected in the "window" object from the "add_init_script" when the BrowserContext initialized.
|
|
||||||
return await page.evaluate("window.__printTriggered")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
async def reset_print_triggered(page: Page) -> bool:
|
|
||||||
"""
|
|
||||||
Get print triggered on the page. Only Page instance could be printed as PDF.
|
|
||||||
"""
|
|
||||||
# the flag was injected in the "window" object from the "add_init_script" when the BrowserContext initialized.
|
|
||||||
return await page.evaluate("() => window.__printTriggered = false")
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def create_instance(cls, frame: Page | Frame) -> SkyvernFrame:
|
async def create_instance(cls, frame: Page | Frame) -> SkyvernFrame:
|
||||||
instance = cls(frame=frame)
|
instance = cls(frame=frame)
|
||||||
|
|||||||
Reference in New Issue
Block a user