You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix alert dialog detection and handling capabilities? #713
There is an issue that was auto-closed for this: #529
However, even today, with running this MCP through Claude Code, I'm having trouble with this functionality.
My use case is simple - when an alert dialog appears on page, the process halts and times outs. The actual handle_dialog() call gets executed only AFTER I manually click OK in the browser (when running interactively - in headless mode, I just have to wait for the timeout). The interesting thing is that this call even thinks it handled the OK button itself - it does not report an error (which is otherwise does, when no dialog is on page because I already clicked OK before handle_dialog could execute but after the MCP found out about a dialog being present on page).
Not sure if this feature is broken only for a handful of us or it's something else but I can confirm that the issue is still there.
what you'd expect - handle_dialog only appears after I press OK, everything else works smoothly afterwards (the call even thinks it handled the OK button itself)
Thanks for reporting, do you have steps to reproduce? Which process is timing out for you? is the dialog caused by a script evaluation tool call or by input?
Just as you commented, I'm running a set of fixes and while trying a fix via MCP, Claude Code has this very issue. Here is where I'm currently stuck:
Claude is instructed to test its fixes in browser. It does this but as it tries to navigate away, the onbeforeunload event hits and displays a leaving message:
And the browser, alongside with Claude get stuck on this page, waiting until a timeout is reached. If I click the Leave button itself, the workflow continues but that basically defeats the purpose and also shows wrong continuation in console (it would appear that Claude has accepted the dialog - but that info is wrong, as the actual navigation timed out while I was writing this comment :-D and then I clicked the Leave button manually):
So this is the exact workflow that fails me and was failing me for a long time now.
Yes, it seems to be specific to onBeforeUnload events. When the handle_dialog() runs, the previous wait for a dialog already timed out (with the dialog still present on page - thus the next retry which followed on the last screenshot above, which also timed out). The handle_dialog() function actually lies, as it never accomplishes anything in this case. When I manually click "Reload" (or "Leave") button, the handle_dialog() function is only presented AFTERWARDS and again lies about it doing anything. So the function actually never fires in time, waiting in a background loop of the onBeforeUnload dialog, never catching it.
I did as instructed and here is the new Claude Code log + I'm attaching the debug log as well (I manually clicked the Reload button this time, I did not wait for a timeout):
There is also another issue which is not handled by handle_dialog() and this one might be even worse for CI, since it blocks Chrome until an OK button is clicked. When a compromised password was found to be entered in a password field, Chrome displays a warning dialog about this after the login is complete:
In this case, the browser is blocked from any keyboard interaction apart from JavaScript, so if I try to change something on page, I can't do it until this is manually clicked on, dev tools devising JS strategies to overcome this, breaking any e2e tests that depend on manipulating an input:
I'm attaching a debug log (from a later run without the CTRL+A step, as I did not record this first try) for this as well.
The change password dialog should be non-blocking but there is unfortunately no way currently to handle it via CDP (it should be possible to disable that in chrome://settings though).
cc @natorion we need to look into the beforeunload dialogs as they seem to block the navigations. cc @sebastianbenz do you know if there is a way to disable password dialogs from the browser?
Yes, this is what happens after you click it manually - the MCP still thinks the dialog is there but it was there for about 30 seconds, then I clicked it and only then the MCP workflow resumed and handle_dialog() realized (late) there is a dialog (which was already gone after I clicked it).
On beforeunload dialogs: What's the behavior in puppeteer for this exact same use case?
it would trigger the dialog and the navigation would time out, same as with the MCP server. In contrast to the MCP server, Puppeteer can handle the event about the dialog during the navigation preventing the time out.
I'm afraid this is still not working for me. I've only had the time to test this just now and I got stuck even at an ordinary JS confirm dialog and had to intervene manually. I can probably provide more info if you need debug, just say the word. I think the onbeforeunload suffers the same fate, unfortunately.
Ah, I see what's happening now. So, this actually DOES work most of the time but FAILS when Claude Code decides to click on a button through JS instead of clicking on it directly via MCP:
... but even from this Claude was able to get unstuck after a timeout - I think it reloaded the page or maybe it actually found the dialog on page afterwards and continued. So I think this is working and I'm not sure whether you can do anything about this JS related issue at all?
@martinambrus yeah it would be tricky unless we want to configure the dialog behavior for scripts similar to the navigation tool. What happens I believe is that on click the dialog shows up and blocks the rest of the JS execution (the 'return' part) so the script probably times out. Let me file a new feature request for this.
Yeah this is driving me mad too - it cant close any dialog and takes sometimes several minutes to do it when it actually can, sometimes it just completely locks up and I have to do it manually at which point it continues
Ah, I see what's happening now. So, this actually DOES work most of the time but FAILS when Claude Code decides to click on a button through JS instead of clicking on it directly via MCP:
... but even from this Claude was able to get unstuck after a timeout - I think it reloaded the page or maybe it actually found the dialog on page afterwards and continued. So I think this is working and I'm not sure whether you can do anything about this JS related issue at all?
This is the same behaviour that is happening in my current open ticket #1609 - the dialog blocks take_snapshot from being able to be run which ultimately halts the entire process.
I think it would be worthwhile to add this case to our skills. Something like "If you are actuating a dialog, use tools xya, not evaluate_script". or similar.
Activity
OrKoN commentedon Jan 7, 2026
Thanks for reporting, do you have steps to reproduce? Which process is timing out for you? is the dialog caused by a script evaluation tool call or by input?
martinambrus commentedon Jan 7, 2026
Just as you commented, I'm running a set of fixes and while trying a fix via MCP, Claude Code has this very issue. Here is where I'm currently stuck:
Claude is instructed to test its fixes in browser. It does this but as it tries to navigate away, the onbeforeunload event hits and displays a leaving message:
And the browser, alongside with Claude get stuck on this page, waiting until a timeout is reached. If I click the Leave button itself, the workflow continues but that basically defeats the purpose and also shows wrong continuation in console (it would appear that Claude has accepted the dialog - but that info is wrong, as the actual navigation timed out while I was writing this comment :-D and then I clicked the Leave button manually):
So this is the exact workflow that fails me and was failing me for a long time now.
OrKoN commentedon Jan 7, 2026
Thanks, it sounds like it might be specific to before unload dialogs. So when the handle_dialog runs, the dialog on screen does not close? or does it close but gets triggered again by the next navigate call? Seeing https://github.com/ChromeDevTools/chrome-devtools-mcp/blob/main/src/tools/pages.ts#L256 would it be possible for you to record a log file and see if there are errors when handling the dialog? https://github.com/ChromeDevTools/chrome-devtools-mcp/blob/main/docs/troubleshooting.md#debugging
martinambrus commentedon Jan 7, 2026
Yes, it seems to be specific to onBeforeUnload events. When the handle_dialog() runs, the previous wait for a dialog already timed out (with the dialog still present on page - thus the next retry which followed on the last screenshot above, which also timed out). The handle_dialog() function actually lies, as it never accomplishes anything in this case. When I manually click "Reload" (or "Leave") button, the handle_dialog() function is only presented AFTERWARDS and again lies about it doing anything. So the function actually never fires in time, waiting in a background loop of the onBeforeUnload dialog, never catching it.
I did as instructed and here is the new Claude Code log + I'm attaching the debug log as well (I manually clicked the Reload button this time, I did not wait for a timeout):
There is also another issue which is not handled by handle_dialog() and this one might be even worse for CI, since it blocks Chrome until an OK button is clicked. When a compromised password was found to be entered in a password field, Chrome displays a warning dialog about this after the login is complete:
In this case, the browser is blocked from any keyboard interaction apart from JavaScript, so if I try to change something on page, I can't do it until this is manually clicked on, dev tools devising JS strategies to overcome this, breaking any e2e tests that depend on manipulating an input:
I'm attaching a debug log (from a later run without the CTRL+A step, as I did not record this first try) for this as well.
chromedev-compromises-password.log
chromedev-onbeforeunload.log
OrKoN commentedon Jan 7, 2026
The change password dialog should be non-blocking but there is unfortunately no way currently to handle it via CDP (it should be possible to disable that in chrome://settings though).
OrKoN commentedon Jan 7, 2026
I see that there was an attempt to handle the dialog but it was not showing (I guess because you clicked it manually?):
OrKoN commentedon Jan 7, 2026
cc @natorion we need to look into the beforeunload dialogs as they seem to block the navigations. cc @sebastianbenz do you know if there is a way to disable password dialogs from the browser?
martinambrus commentedon Jan 7, 2026
Yes, this is what happens after you click it manually - the MCP still thinks the dialog is there but it was there for about 30 seconds, then I clicked it and only then the MCP workflow resumed and handle_dialog() realized (late) there is a dialog (which was already gone after I clicked it).
natorion commentedon Jan 7, 2026
On beforeunload dialogs: What's the behavior in puppeteer for this exact same use case?
OrKoN commentedon Jan 8, 2026
it would trigger the dialog and the navigation would time out, same as with the MCP server. In contrast to the MCP server, Puppeteer can handle the event about the dialog during the navigation preventing the time out.
docs: add comprehensive AI technical gotchas guide for MCP builders
fix: handle beforeunload dialogs in navigations (#788)
martinambrus commentedon Jan 19, 2026
excellent, thank you, I'll test it as soon as new release is out :)
martinambrus commentedon Feb 9, 2026
I'm afraid this is still not working for me. I've only had the time to test this just now and I got stuck even at an ordinary JS confirm dialog and had to intervene manually. I can probably provide more info if you need debug, just say the word. I think the onbeforeunload suffers the same fate, unfortunately.
OrKoN commentedon Feb 9, 2026
The onbeforeunload should be no automatically dismissed during navigations (see the test added it in https://github.com/ChromeDevTools/chrome-devtools-mcp/pull/788/changes#diff-a07f4b41269b9940c07bb55403b662aefe62124c9139bc3d0849d632e428242f). Please provide some details of what you are seeing with the latest version.
martinambrus commentedon Feb 9, 2026
Ah, I see what's happening now. So, this actually DOES work most of the time but FAILS when Claude Code decides to click on a button through JS instead of clicking on it directly via MCP:
... but even from this Claude was able to get unstuck after a timeout - I think it reloaded the page or maybe it actually found the dialog on page afterwards and continued. So I think this is working and I'm not sure whether you can do anything about this JS related issue at all?
OrKoN commentedon Feb 9, 2026
@martinambrus yeah it would be tricky unless we want to configure the dialog behavior for scripts similar to the navigation tool. What happens I believe is that on click the dialog shows up and blocks the rest of the JS execution (the 'return' part) so the script probably times out. Let me file a new feature request for this.
voycey commentedon Feb 19, 2026
Yeah this is driving me mad too - it cant close any dialog and takes sometimes several minutes to do it when it actually can, sometimes it just completely locks up and I have to do it manually at which point it continues
voycey commentedon Mar 23, 2026
This is the same behaviour that is happening in my current open ticket #1609 - the dialog blocks take_snapshot from being able to be run which ultimately halts the entire process.
natorion commentedon Mar 23, 2026
I think it would be worthwhile to add this case to our skills. Something like "If you are actuating a dialog, use tools xya, not evaluate_script". or similar.
fix: handle beforeunload dialogs in navigations (#788)