Skip to content

Fix alert dialog detection and handling capabilities? #713

Closed

Description

@martinambrus

Description of the bug

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.

Reproduction

Please see #529

Expectation

Please see #529

MCP configuration

{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--channel=stable",
"--isolated=true",
"--viewport=1920x1080"
]
}
}
}

Chrome DevTools MCP version

current, latest

Chrome version

143.0.7499.169

Coding agent version

2.0.76

Model version

opus, sonnet, haiku - all of them

Chat log

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)

Node version

24.12.0

Operating system

Windows Subsystem for Linux (WSL)

Extra checklist

  • I want to provide a PR to fix this bug

Activity

  1. added theissue type on Dec 27, 2025
  2. OrKoN commented on Jan 7, 2026

    @OrKoN
    Collaborator

    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?

  3. martinambrus commented on Jan 7, 2026

    @martinambrus
    Author

    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:

    Image

    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:

    Image

    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):

    Image

    So this is the exact workflow that fails me and was failing me for a long time now.

  4. OrKoN commented on Jan 7, 2026

    @OrKoN
    Collaborator

    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

  5. martinambrus commented on Jan 7, 2026

    @martinambrus
    Author

    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):

    Image

    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:

    Image

    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:

    Image

    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

  6. OrKoN commented on Jan 7, 2026

    @OrKoN
    Collaborator

    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).

  7. OrKoN commented on Jan 7, 2026

    @OrKoN
    Collaborator

    I see that there was an attempt to handle the dialog but it was not showing (I guess because you clicked it manually?):

    2026-01-07T13:56:32.667Z puppeteer:protocol:SEND ► [
      '{"method":"Page.handleJavaScriptDialog","params":{"accept":false},"id":180,"sessionId":"D47DD0BA5BFEFBEE3FF7EBDB67426204"}'
    ]
    2026-01-07T13:56:32.668Z puppeteer:protocol:RECV ◀ [
      '{"id":180,"error":{"code":-32602,"message":"No dialog is showing"},"sessionId":"D47DD0BA5BFEFBEE3FF7EBDB67426204"}'
    ]
    
  8. OrKoN commented on Jan 7, 2026

    @OrKoN
    Collaborator

    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?

  9. martinambrus commented on Jan 7, 2026

    @martinambrus
    Author

    I see that there was an attempt to handle the dialog but it was not showing (I guess because you clicked it manually?):

    2026-01-07T13:56:32.667Z puppeteer:protocol:SEND ► [
      '{"method":"Page.handleJavaScriptDialog","params":{"accept":false},"id":180,"sessionId":"D47DD0BA5BFEFBEE3FF7EBDB67426204"}'
    ]
    2026-01-07T13:56:32.668Z puppeteer:protocol:RECV ◀ [
      '{"id":180,"error":{"code":-32602,"message":"No dialog is showing"},"sessionId":"D47DD0BA5BFEFBEE3FF7EBDB67426204"}'
    ]
    

    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).

  10. natorion commented on Jan 7, 2026

    @natorion
    Contributor

    On beforeunload dialogs: What's the behavior in puppeteer for this exact same use case?

  11. OrKoN commented on Jan 8, 2026

    @OrKoN
    Collaborator

    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.

  12. martinambrus commented on Jan 19, 2026

    @martinambrus
    Author

    excellent, thank you, I'll test it as soon as new release is out :)

  13. martinambrus commented on Feb 9, 2026

    @martinambrus
    Author

    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.

  14. OrKoN commented on Feb 9, 2026

    @OrKoN
    Collaborator

    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.

  15. martinambrus commented on Feb 9, 2026

    @martinambrus
    Author

    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:

    chrome-devtools - take_snapshot (MCP)                                                                                                                                                                    
                                                                                                                                                                                                                  
         chrome-devtools - evaluate_script (MCP)(function: "() => {\n  const btn = document.getElementById('edit-bulk-apply');\n  if (btn) {\n    btn.click();\n    return 'clicked edit-bulk-apply';\n  }\n  //  
    

    ... 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?

  16. OrKoN commented on Feb 9, 2026

    @OrKoN
    Collaborator

    @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.

  17. voycey commented on Feb 19, 2026

    @voycey

    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

  18. voycey commented on Mar 23, 2026

    @voycey

    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:

    chrome-devtools - take_snapshot (MCP)                                                                                                                                                                    
                                                                                                                                                                                                                  
         chrome-devtools - evaluate_script (MCP)(function: "() => {\n  const btn = document.getElementById('edit-bulk-apply');\n  if (btn) {\n    btn.click();\n    return 'clicked edit-bulk-apply';\n  }\n  //  
    

    ... 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.

  19. natorion commented on Mar 23, 2026

    @natorion
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions