Repository navigation
fix(console): keep stack traces of messages from earlier navigations - #3397
Conversation
createStackTrace() waits up to 1 s for each script of a stack trace, but its .catch() had no handler, so a script that never showed up made it throw and the callers dropped the whole stack. DevTools drops the old page's scripts on navigation, so console messages and uncaught errors from earlier navigations lost their stack trace whenever one of their script ids was not in use on the new page. Script ids are only unique within a renderer process, so after a cross-site navigation the id of an old frame can belong to a script of the new page, and DevTools resolved the frame against that script. createStackTrace() now uses a script that it finds by id only when the script has the frame's URL (V8 leaves data: URLs out of stack frames). The other frames get script id 0, which V8 never assigns, so DevTools keeps their raw location. Frames without a UISourceCode printed their raw 0-based line and column. formatFrame() now prints them like UILocation.linkText(): line and column 1-based, and frames of wasm:// modules as a hex byte offset.
…ed-stack-traces Resolve the conflict in createStackTrace() with the waitForSourceMaps() refactor from ChromeDevTools#3211: the per-script wait keeps its catch and URL check, and only the scripts that match their frames' URLs go to waitForSourceMaps() and keep their script ids.
|
Merged #3211 moved the source-map wait of Tests on Windows 11 (Node 24.20, Chrome 156), built with
|
|
@szuend could you please take a look at this PR? |
OrKoN
left a comment
There was a problem hiding this comment.
I think #3396 would not be fully fixed with this. I think the best fix is to have unique ids for scripts coming from v8. I think we can land this but we need long term improvements as well (please update description to remove that the issue is fixed). Also, please check the following:
- Add a test for an uncaught error and a test for
get_console_messageafter a navigation intests/tools/console.test.ts. The PR description claims both paths, but the two new tests cover onlyconsole.loginlist_console_messages. - Add a mock frame with a
wasm://URL totests/formatters/ConsoleFormatter.test.ts. The hex-offset branch offormatFrame()has only a real-browser test, andAGENTS.mdprefers mock-based unit tests. - Make
keeps preserved frames raw after a cross-site navigationfail when the new page does not reuse the old script ids. Without a collision, the 1 s timeout path prints the same raw frame, so the test passes without the URL check.
…ed-stack-traces # Conflicts: # tests/tools/console.test.ts
…ames Add a test for the stack trace of an uncaught error from before a navigation in list_console_messages, a test for the stack trace of a message in get_console_message after a navigation, and a mock frame with a wasm:// URL to the ConsoleFormatter tests for the hex byte offset that formatFrame() prints.
The test passed without the URL check in createStackTrace() when the new page did not reuse the old script ids, because the frame then also stays raw after the 1 s wait for its script. Check that a script of the new page has the old frame's script id before checking the frame, and log from an inline script, which gets the same id on every run, instead of a script from the network.
|
I updated the description: it now says this PR addresses part of #3396 (the stack traces lost after a navigation) and that unique script ids from V8 are the long-term fix. I also merged
|
🤖 I have created a release *beep* *boop* --- ## [1.14.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.13.0...chrome-devtools-mcp-v1.14.0) (2026-11-24) ### 🎉 Features * add --backgroundNewPages to keep new_page tabs in the background ([ChromeDevTools#3539](ChromeDevTools#3539)) ([7a39d6d](ChromeDevTools@7a39d6d)) * add abort and allow-origin network mocks ([ChromeDevTools#3421](ChromeDevTools#3421)) ([eb4b53d](ChromeDevTools@eb4b53d)) * add inspect-in-devtools skill and claude plugin command ([ChromeDevTools#2696](ChromeDevTools#2696)) ([aa977a6](ChromeDevTools@aa977a6)) * add network requests from service workers ([ChromeDevTools#3554](ChromeDevTools#3554)) ([11162da](ChromeDevTools@11162da)) * add service workers to get_console_message ([ChromeDevTools#3537](ChromeDevTools#3537)) ([2e247a4](ChromeDevTools@2e247a4)) * include computed styles in get_css_styles ([ChromeDevTools#3538](ChromeDevTools#3538)) ([cf98d8b](ChromeDevTools@cf98d8b)) * list errors a page raises while a tool runs ([ChromeDevTools#3431](ChromeDevTools#3431)) ([d5d30bd](ChromeDevTools@d5d30bd)) * resolve CSS custom variable values inline in `get_css_styles` ([ChromeDevTools#3481](ChromeDevTools#3481)) ([8ba2ac9](ChromeDevTools@8ba2ac9)) * support transparent screenshots ([ChromeDevTools#3457](ChromeDevTools#3457)) ([045fb8c](ChromeDevTools@045fb8c)) * **telemetry:** send startup events directly from the server process ([ChromeDevTools#3511](ChromeDevTools#3511)) ([b14eb81](ChromeDevTools@b14eb81)) ### 🛠️ Fixes * accept POSIX root URIs from WSL2 clients on a Windows server ([ChromeDevTools#3380](ChromeDevTools#3380)) ([4b9acc9](ChromeDevTools@4b9acc9)) * align root plugin.json name with marketplace entry ([ChromeDevTools#3474](ChromeDevTools#3474)) ([1424980](ChromeDevTools@1424980)) * **cli:** enable off by default categories in CLI except PWA ([ChromeDevTools#3595](ChromeDevTools#3595)) ([0ff265d](ChromeDevTools@0ff265d)) * **cli:** handle array of strings correctly ([ChromeDevTools#3593](ChromeDevTools#3593)) ([d197b28](ChromeDevTools@d197b28)) * **cli:** match yargs-parser when detecting negative numbers ([ChromeDevTools#3548](ChromeDevTools#3548)) ([eb9b030](ChromeDevTools@eb9b030)) * **cli:** pass option values starting with `-` through to tools ([ChromeDevTools#3501](ChromeDevTools#3501)) ([ec0abfc](ChromeDevTools@ec0abfc)) * **cli:** preserve daemon PID when SIGKILL fails ([ChromeDevTools#3485](ChromeDevTools#3485)) ([0788697](ChromeDevTools@0788697)) * **cli:** reuse live daemons after EPERM ([ChromeDevTools#3452](ChromeDevTools#3452)) ([1417f93](ChromeDevTools@1417f93)) * **cli:** strip terminal escape sequences from tool output and errors ([ChromeDevTools#3536](ChromeDevTools#3536)) ([ec2fb15](ChromeDevTools@ec2fb15)) * **config:** reject --browserUrl values without an http(s) scheme ([ChromeDevTools#3437](ChromeDevTools#3437)) ([e40cef6](ChromeDevTools@e40cef6)) * **config:** reject --viewport values with more than two parts ([ChromeDevTools#3577](ChromeDevTools#3577)) ([ab911a6](ChromeDevTools@ab911a6)) * **console:** keep stack traces of messages from earlier navigations ([ChromeDevTools#3397](ChromeDevTools#3397)) ([e8798d6](ChromeDevTools@e8798d6)) * **console:** resolve Error arguments on the session of their handle ([ChromeDevTools#3408](ChromeDevTools#3408)) ([4c6c767](ChromeDevTools@4c6c767)) * dedicated worker can now build a stack trace ([ChromeDevTools#3572](ChromeDevTools#3572)) ([9762165](ChromeDevTools@9762165)), closes [ChromeDevTools#2962](ChromeDevTools#2962) * do not queue unknown page ids ([ChromeDevTools#3599](ChromeDevTools#3599)) ([4dc8cbc](ChromeDevTools@4dc8cbc)) * **emulation:** reject non-string extraHttpHeaders values ([ChromeDevTools#3484](ChromeDevTools#3484)) ([64d4726](ChromeDevTools@64d4726)) * explain DevToolsActivePort permission errors during autoConnect ([ChromeDevTools#3487](ChromeDevTools#3487)) ([0e49c59](ChromeDevTools@0e49c59)) * **extensions:** preserve list_extensions fields in JSON output ([ChromeDevTools#3592](ChromeDevTools#3592)) ([02b146b](ChromeDevTools@02b146b)) * **input:** allow multi-file upload_file through chooser-opening elements ([ChromeDevTools#3436](ChromeDevTools#3436)) ([ef680a3](ChromeDevTools@ef680a3)) * **input:** return when click_at, type_text, drag or press_key opens a dialog ([ChromeDevTools#3576](ChromeDevTools#3576)) ([7bcb86d](ChromeDevTools@7bcb86d)) * keep temp files under the temp dir ([ChromeDevTools#3372](ChromeDevTools#3372)) ([d666acf](ChromeDevTools@d666acf)) * remove commands from claude plugin ([ChromeDevTools#3469](ChromeDevTools#3469)) ([e2f08b4](ChromeDevTools@e2f08b4)) * respect tool timeouts in CLI daemon responses ([ChromeDevTools#3443](ChromeDevTools#3443)) ([86a1c23](ChromeDevTools@86a1c23)) * **snapshot:** keep extra element UIDs reusable ([ChromeDevTools#3493](ChromeDevTools#3493)) ([4559cd5](ChromeDevTools@4559cd5)) * treat local host name and interface addresses as local browser endpoints ([ChromeDevTools#3463](ChromeDevTools#3463)) ([cf587b4](ChromeDevTools@cf587b4)) * use exception events instead of Runtime.exceptionThrown ([ChromeDevTools#3553](ChromeDevTools#3553)) ([437f394](ChromeDevTools@437f394)) * validate heap snapshot className regex ([ChromeDevTools#3030](ChromeDevTools#3030)) ([343e6b1](ChromeDevTools@343e6b1)) * validate install_pwa and launch_pwa URLs against navigation policy ([ChromeDevTools#3464](ChromeDevTools#3464)) ([057a6aa](ChromeDevTools@057a6aa)) * wait for parsed scripts before reporting an unknown logpoint URL ([ChromeDevTools#3461](ChromeDevTools#3461)) ([404f331](ChromeDevTools@404f331)) ### 📄 Documentation * clarify that Chrome may clamp resize_page dimensions ([ChromeDevTools#3583](ChromeDevTools#3583)) ([b5a41e0](ChromeDevTools@b5a41e0)), closes [ChromeDevTools#2998](ChromeDevTools#2998) * explain the light and browser third-party bundles in AGENTS.md ([ChromeDevTools#3529](ChromeDevTools#3529)) ([835c09a](ChromeDevTools@835c09a)) * fix typos in comments, tests and skill docs ([ChromeDevTools#3489](ChromeDevTools#3489)) ([f312b72](ChromeDevTools@f312b72)) ### ⚡ Performance * **telemetry:** start the watchdog process on the first event that needs it ([ChromeDevTools#3513](ChromeDevTools#3513)) ([a4c550d](ChromeDevTools@a4c550d)) ### 🏗️ Refactor * **build:** split Puppeteer and DevTools into a separate bundle ([ChromeDevTools#3510](ChromeDevTools#3510)) ([1067857](ChromeDevTools@1067857)) * **config:** import ConfigWatcher without the browser bundle ([ChromeDevTools#3520](ChromeDevTools#3520)) ([24dba69](ChromeDevTools@24dba69)) * create BrowserManager without the browser bundle ([ChromeDevTools#3563](ChromeDevTools#3563)) ([e8763f9](ChromeDevTools@e8763f9)) * **formatters:** rename MAX_NAME_LENGTH to HEAP_SNAPSHOT_MAX_NAME_LENGTH ([ChromeDevTools#3591](ChromeDevTools#3591)) ([92250bc](ChromeDevTools@92250bc)) * load DevTools in HeapSnapshotManager on first use ([ChromeDevTools#3564](ChromeDevTools#3564)) ([d8035c6](ChromeDevTools@d8035c6)) * load McpResponse when ToolHandler builds a response ([ChromeDevTools#3565](ChromeDevTools#3565)) ([e4669b3](ChromeDevTools@e4669b3)) * **telemetry:** extract sending to Clearcut into sendToClearcut() ([ChromeDevTools#3509](ChromeDevTools#3509)) ([7354c59](ChromeDevTools@7354c59)) * **telemetry:** generate the session id in ClearcutLogger ([ChromeDevTools#3516](ChromeDevTools#3516)) ([ea19ce7](ChromeDevTools@ea19ce7)) * **telemetry:** import flagUtils without the browser bundle ([ChromeDevTools#3518](ChromeDevTools#3518)) ([ab046de](ChromeDevTools@ab046de)) * **third_party:** re-export Mutex from the light bundle ([ChromeDevTools#3566](ChromeDevTools#3566)) ([48466c4](ChromeDevTools@48466c4)) * **tools:** import emulation without the browser bundle ([ChromeDevTools#3521](ChromeDevTools#3521)) ([c5d5d7f](ChromeDevTools@c5d5d7f)) * **tools:** import input without the browser bundle ([ChromeDevTools#3522](ChromeDevTools#3522)) ([bdecb63](ChromeDevTools@bdecb63)) * **tools:** import logpoints without the browser bundle ([ChromeDevTools#3525](ChromeDevTools#3525)) ([71098b0](ChromeDevTools@71098b0)) * **tools:** import memory without the browser bundle ([ChromeDevTools#3526](ChromeDevTools#3526)) ([ebb27f9](ChromeDevTools@ebb27f9)) * **tools:** import performance without the browser bundle ([ChromeDevTools#3524](ChromeDevTools#3524)) ([ba76587](ChromeDevTools@ba76587)) * **tools:** import snapshot without the browser bundle ([ChromeDevTools#3523](ChromeDevTools#3523)) ([110d7f3](ChromeDevTools@110d7f3)) * **utils:** import text utilities without the browser bundle ([ChromeDevTools#3519](ChromeDevTools#3519)) ([8029df8](ChromeDevTools@8029df8)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Addresses part of #3396: the stack traces that console messages and uncaught errors lose after a navigation. It does not fully fix the issue. Script ids are only unique within a renderer process, so a frame's script id alone can't tell which script the frame came from: this PR keeps a frame raw when its script is gone or when the script with its id has another URL, and frames of scripts without a URL are still resolved by id alone. The long-term fix is unique ids for scripts from V8.
After a navigation or reload, console messages and uncaught errors from the previous page lose their whole stack trace:
list_console_messageswithincludePreservedMessagesandincludeStackTracesprints noat ...lines for them, andget_console_messagehas no### Stack tracesection. After a navigation to another site, they can instead get the frames of the new page's scripts.Cause
createStackTrace()waits up to 1 s for each script of the stack trace, with aPromise.alloverwaitForScript()that has no handler, and then for their source maps (waitForSourceMaps()). When a script doesn't show up within the 1 s,Promise.allrejects with the timeout andcreateStackTrace()throws.ConsoleFormatter.from()andSymbolizedErrorcatch that and drop the stack. DevTools drops the old page's scripts on navigation, so for a message from an earlier navigation the wait times out as soon as one of its script ids is not in use on the current page.Script ids are only unique within a renderer process, and the process of a new site numbers its scripts from the start again. When every script id of an old stack is in use again, nothing times out, and DevTools resolves the old frames against the new page's scripts.
The MCP rebuilds a preserved message's stack trace on every tool call, after DevTools has dropped that page's scripts, and
createStackTraceFromProtocolRuntimeresolves each frame by its script id against the current page's scripts. That is why the URL check below sits increateStackTrace(), which hands the frames to it.Change
createStackTrace()uses a script that it finds by id only when the script's URL is the frame's URL. V8 reports the frames ofdata:scripts with an empty URL, so adata:script matches a frame without a URL. All other frames get script id0, which V8 never assigns, so DevTools keeps their raw URL and position. An empty id would not keep them raw: DevTools then looks the frame up by URL, which after a reload finds the new copy of the script and maps the old position through that copy's source map once it is loaded.formatFrameprinted raw frames, which have noUISourceCode, with their 0-based line and column, while mapped frames go throughUILocation.linkText()and the output says "line and column numbers use 1-based indexing". It now prints them likelinkText()does: line and column 1-based, and frames ofwasm://modules as a hex byte offset. Without this,logFromAbelow would print ashttp://127.0.0.1:PORT/a.js:1:10.What changes for users:
list_console_messages(includePreservedMessageswithincludeStackTraces) andget_console_message. Their frames show the script URL and the raw position, 1-based:a.js:2:11becomeshttp://127.0.0.1:PORT/a.js:2:11);at bar (main.js:3:11)becomesat n (http://127.0.0.1:PORT/main.min.js:1:22));wasm://modules: the byte offset in hex (c9772ffe:0x2dbecomeswasm://wasm/c9772ffe:0x2d). A module compiled from a URL (WebAssembly.instantiateStreaming) has that URL in its frames, so once its script is gone they print line and column.//# sourceURL,data:scripts) have no URL to compare, so they are still resolved by id alone.set_logpoints) from an earlier navigation also gets its stack trace back. Its first frame is then the logpoint expression,at eval (debugger://logpoint:1:N), which DevTools hides only while the page's scripts exist.Promise.then) are not shown, and frames of scripts without a URL (data:,evalwithout//# sourceURL,new Function) show only their function name. Async parts that V8 sends with the stack trace, like--- setTimeout ---, are shown.Built server (
--headless --isolated),list_console_messageswithincludePreservedMessagesandincludeStackTracesafternavigate_pageaway from a page whosea.jslogs inlogFromA()and throws inthrowFromA()(output trimmed to those two messages):With this PR, the navigation to
c.htmlprints the same frames as the one tob.html, without the wait. Before the navigation the frames print asa.js:2:11anda.js:6:9. After a reload, the messages from before the reload print the same frames as after the navigation tob.html.Tests
tests/tools/console.test.ts, with a real browser, because DevTools only drops the scripts on a real navigation and only a new renderer process reuses script ids. Each test fails onmain:list_console_messages>includes preserved stack traces with wasm byte offsets: a page logs fromlogIt()inlogger.jsand from a wasm module, then navigates within the site.list_console_messageswithincludePreservedMessagesandincludeStackTracesmust showat logIt (...logger.js:2:11)andat $run (wasm://wasm/<hash>:0x2d). On main it shows no stack lines.list_console_messages>includes preserved stack traces of uncaught errors: a page throws fromthrowFromOld()inthrower.js, then navigates within the site. The uncaught error must be followed byat throwFromOld (http://127.0.0.1:PORT/thrower.js:2:9). On main it has no stack lines.list_console_messages>keeps preserved frames raw after a cross-site navigation: a page on127.0.0.1logs fromlogFromOld()in an inline script, then navigates to alocalhostpage with eight inline scripts. The test first checks that the old frame's script id now belongs to a script of the new page (DebuggerModel.scriptForId()), then that the old frame prints asat logFromOld (http://127.0.0.1:PORT/old.html:3:11). On main, and with only the URL check removed, it printsat logFromOld (new.html:3:11). If the new page doesn't reuse the id, the first check fails. The old frame comes from an inline script because a script from the network doesn't get the same id on every run.get_console_message>keeps the stack trace of a message after a navigation: a page logs fromlogFromOld()inold.js, then navigates within the site.get_console_messagemust show### Stack tracefollowed byat logFromOld (http://127.0.0.1:PORT/old.js:2:11). On main it has no### Stack tracesection.tests/formatters/ConsoleFormatter.test.ts>formats the position of a wasm frame as a hex byte offset: mock frames ofwasm://wasm/c9772ffe(line 0, column 45) andmain.js(line 4, column 12) must print aswasm://wasm/c9772ffe:0x2dandmain.js:5:13. On main they print aswasm://wasm/c9772ffe:0:45andmain.js:4:12, and without thewasm://branch the first one prints aswasm://wasm/c9772ffe:1:46.UISourceCode, so I regeneratedConsoleFormatter.test.js.snapshot. Each of the 89 changed lines only shifts those positions by one (e.g.foo.ts:10:2tofoo.ts:11:3,main.js:0:0tomain.js:1:1); the wasm test adds two entries.main(with feat: add service workers to get_console_message #3537), on Windows 11 (Node 24.20, Chrome 157):tests/tools/console.test.tspasses (35/35), and so dotests/formatters/ConsoleFormatter.test.ts,tests/formatters/ConsoleFormatterGrouping.test.ts,tests/devtools/DevtoolsUtils.test.tsandtests/LogpointManager.test.ts(94/94). The four navigation tests passed 20 runs in a row.npm run check-formatis clean, andnpm run genisn't needed (no schema, description or CLI change). The GNnpm run buildneeds more disk than this machine had, so I bundled the test files with esbuild and ran them throughnode scripts/test.js.