Repository navigation
Description
Description of the bug
After the page navigates, console messages and uncaught errors from the previous page lose their whole stack trace:
list_console_messageswithincludePreservedMessages: trueandincludeStackTraces: truelists them without anyat ...lines.get_console_messagefor one of them has no### Stack tracesection.
Before the navigation, the same messages have full stack traces. After it, each of these calls first waits about 1 s for the old page's scripts. A reload does the same: the messages logged before it lose their stack, while the identical messages logged after it keep theirs.
After a navigation to another site, the old messages can instead get the frames of the new page's scripts. In the reproduction below, logFromA from a.js is then printed as a frame of c1.js, a script of the new page.
createStackTrace() (src/devtools/DevtoolsUtils.ts) waits up to 1 s for every script in the stack trace, but the .catch() on that wait has no handler, so it doesn't catch the timeout. DevTools drops the old page's scripts on navigation, so the wait times out as soon as one script id of the stack is not in use on the new page, createStackTrace() throws, and both callers (ConsoleFormatter for console messages, SymbolizedError for uncaught errors) drop the stack.
The wrong frames have another cause: 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.
Adding a handler alone isn't enough: frames of scripts that are gone have no UISourceCode, and formatFrame prints their raw 0-based position (line 1, column 10 instead of a.js:2:11 for logFromA in the reproduction below), while the output says line and column numbers are 1-based.
Reproduction
Serve three files:
a.html:<!doctype html><title>a</title><script src="/a.js"></script>b.html:<!doctype html><title>b</title>a.js:
function logFromA() {
console.log("message from A");
}
logFromA();
function throwFromA() {
throw new Error("uncaught from A");
}
setTimeout(throwFromA, 0);Then call the tools (output trimmed to the two messages from a.js):
new_page {"url": "http://127.0.0.1:PORT/a.html"}
list_console_messages {"pageId": 2, "includeStackTraces": true}
msgid=1 [log] message from A (1 args)
at logFromA (a.js:2:11)
at (a.js:4:1)
msgid=2 [error] Uncaught Error: uncaught from A (0 args)
at throwFromA (a.js:6:9)
--- setTimeout -------------------------
at (a.js:8:1)
navigate_page {"pageId": 2, "type": "url", "url": "http://127.0.0.1:PORT/b.html"}
list_console_messages {"pageId": 2, "includePreservedMessages": true, "includeStackTraces": true}
(took 1003 ms)
msgid=1 [log] message from A (1 args)
msgid=2 [error] Uncaught Error: uncaught from A (0 args)
get_console_message {"pageId": 2, "msgid": 1}
(took 1004 ms)
ID: 1
Message: log> message from A
### Arguments
Arg #0: message from A
get_console_message {"pageId": 2, "msgid": 2}
(took 1007 ms)
ID: 2
Message: error> Uncaught Error: uncaught from A
With navigate_page {"pageId": 2, "type": "reload"} instead of the navigation to b.html (msgid 3, a Failed to load resource 404, left out):
list_console_messages {"pageId": 2, "includePreservedMessages": true, "includeStackTraces": true}
(took 1005 ms)
msgid=1 [log] message from A (1 args)
msgid=2 [error] Uncaught Error: uncaught from A (0 args)
msgid=4 [log] message from A (1 args)
at logFromA (a.js:2:11)
at (a.js:4:1)
msgid=5 [error] Uncaught Error: uncaught from A (0 args)
at throwFromA (a.js:6:9)
--- setTimeout -------------------------
at (a.js:8:1)
For another site, serve c.html and four small scripts from the same server and open c.html through localhost instead of 127.0.0.1:
c.html:<!doctype html><title>c</title><script src="/c1.js"></script><script src="/c2.js"></script><script src="/c3.js"></script><script src="/c4.js"></script>c1.jstoc4.js, the same for each number:
function fromC1() {
return 1;
}
fromC1();With navigate_page {"pageId": 2, "type": "url", "url": "http://localhost:PORT/c.html"} instead of the navigation to b.html:
list_console_messages {"pageId": 2, "includePreservedMessages": true, "includeStackTraces": true}
(took 3 ms)
msgid=1 [log] message from A (1 args)
at logFromA (c1.js:2:11)
at (c1.js:4:1)
msgid=2 [error] Uncaught Error: uncaught from A (0 args)
at throwFromA (c1.js:6:9)
--- setTimeout -------------------------
at (c1.js:8:1)
Expectation
Messages from an earlier navigation keep their stack traces. Their scripts are gone, so the frames can't be mapped any more, but each frame still has its URL, line and column, so logFromA should print as at logFromA (http://127.0.0.1:PORT/a.js:2:11), 1-based like the rest of the output. For a plain script like a.js that is the same position as before the navigation. No frame should be printed as a frame of a different script that reuses its script id.
MCP configuration
--headless --isolated --no-usage-statistics
Chrome DevTools MCP version
main at 8d009e8 (local build, 1.12.0)
Chrome version
156.0.8078.79
Node version
24.20.0
Operating system
Windows
Extra checklist
- I want to provide a PR to fix this bug
Activity
tlq5l commentedon Nov 4, 2026
Reproduced (agent-run, 2026-11-04) with chrome-devtools-mcp 1.12.0 (the reported version, also the latest npm release) and Chrome 157.0.8103.38.
Steps: new_page a.html (it logs a message and throws an uncaught error), navigate to b.html, then list_console_messages with includeStackTraces.
Result: before the navigation, the message and the error from a.js print their stack frames. After it, both print without frames. get_console_message on the message also has no frames.
Not run: the wrong-frame case across sites from the report.
Suspected, from the report and not checked in source: createStackTrace() in src/devtools/DevtoolsUtils.ts drops the stack when the 1 s script wait's .catch() times out, and reused script ids resolve old frames against the new page.
fix(console): keep stack traces of messages from earlier navigations (C…
yulunz commentedon Dec 2, 2026
Status update after #3397 landed (
e8798d6):Done (fix(console): keep stack traces of messages from earlier navigations #3397):
list_console_messages(includePreservedMessages+includeStackTraces) andget_console_messageinstead of dropping them on script-wait timeout.createStackTrace()checks that a script matched by ID has the same URL as the frame, preventing old frames from resolving against unrelated scripts on a new page after a cross-site navigation.wasm://).Still remaining:
evalwithout//# sourceURL,new Function,data:scripts) have no URL to compare and can still collide by script ID. The long-term fix is unique script IDs from V8.