From 28fe49c2b2081847c93f7b31e26bde5286ca9a39 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 10 Jul 2024 12:04:32 -0500 Subject: [PATCH] xactfetch: Save Playwright trace for failed runs Playwright has a nifty feature called the [Trace Viewer][0], which you can use to observe the state of the page at any given point during the browsing session. This should make troubleshooting failures a lot easier. [0]: https://playwright.dev/python/docs/trace-viewer-intro --- xactfetch.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xactfetch.py b/xactfetch.py index e0efac5..67a019e 100644 --- a/xactfetch.py +++ b/xactfetch.py @@ -722,7 +722,9 @@ async def amain() -> None: failed = False async with async_playwright() as pw, secrets: browser = await pw.chromium.launch(headless=False) - page = await browser.new_page() + context = await browser.new_context() + await context.tracing.start(screenshots=True, snapshots=True) + page = await context.new_page() banks = sys.argv[1:] or list(ACCOUNTS.keys()) if 'commerce' in banks: if not await download_commerce( @@ -734,6 +736,14 @@ async def amain() -> None: page, secrets, end_date, token, importer ): failed = True + if failed: + await context.tracing.stop(path='trace.zip') + with open('trace.zip', 'rb') as f: + await ntfy( + 'Downloading one or more transaction lists failed.', + attach=f.read(), + filename='trace.zip', + ) raise SystemExit(1 if failed else 0)