From 9bc0240e959b27cca3ff930457da65d50f66e0cd Mon Sep 17 00:00:00 2001 From: Nick Shirokov Date: Sat, 21 Mar 2026 19:32:00 +0300 Subject: [PATCH] fix(web-test): take error screenshot before fetchErrorStack closes modal Move screenshot capture to before fetchErrorStack call in the ACTION_FNS wrapper, so the error modal is still visible on the screenshot. Skip the duplicate screenshot in catch block when one was already taken. Co-Authored-By: Claude Opus 4.6 (1M context) --- .claude/skills/web-test/scripts/run.mjs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.claude/skills/web-test/scripts/run.mjs b/.claude/skills/web-test/scripts/run.mjs index b70e3f00..0860d1a5 100644 --- a/.claude/skills/web-test/scripts/run.mjs +++ b/.claude/skills/web-test/scripts/run.mjs @@ -145,6 +145,13 @@ async function executeScript(code, { noRecord } = {}) { const result = await orig(...args); const errors = result?.errors; if (errors?.modal || errors?.balloon) { + // Screenshot while the error modal is still visible (before fetchErrorStack closes it) + let errorShot; + try { + const png = await exports.screenshot(); + errorShot = resolve(__dirname, '..', 'error-shot.png'); + writeFileSync(errorShot, png); + } catch {} // Try to fetch call stack for modal errors before throwing let stack = null; if (errors?.modal && typeof exports.fetchErrorStack === 'function') { @@ -154,7 +161,7 @@ async function executeScript(code, { noRecord } = {}) { } const msg = errors.modal?.message || errors.balloon?.message || 'Unknown 1C error'; const err = new Error(msg); - err.onecError = { step: name, args, errors, formState: result, stack }; + err.onecError = { step: name, args, errors, formState: result, stack, screenshot: errorShot }; throw err; } return result; @@ -177,13 +184,15 @@ async function executeScript(code, { noRecord } = {}) { try { await browser.stopRecording(); } catch {} } - // Error screenshot - let shotFile; - try { - const png = await browser.screenshot(); - shotFile = resolve(__dirname, '..', 'error-shot.png'); - writeFileSync(shotFile, png); - } catch {} + // Error screenshot (skip if already taken before fetchErrorStack closed the modal) + let shotFile = e.onecError?.screenshot; + if (!shotFile) { + try { + const png = await browser.screenshot(); + shotFile = resolve(__dirname, '..', 'error-shot.png'); + writeFileSync(shotFile, png); + } catch {} + } const result = { ok: false, error: e.message, output: output.join('\n'), screenshot: shotFile, elapsed: elapsed(t0) };