Skip to content

[🐛 Bug]: "Leave site" dialog is not properly handled when using BiDi protocol #14823

@alexanderjkremer

Description

@alexanderjkremer

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.20.0

Node.js Version

22.14.0

Mode

WDIO Testrunner

Which capabilities are you using?

{
  browserName: 'chrome'
}

What happened?

When attempting to navigate away from a page with a beforeunload event listener using browser.url while using the BiDi protocol the following error is thrown. Even though the navigation to the new URL was successful - this still fails the test.

Unhandled promise rejection: Error: WebDriver Bidi command "browsingContext.handleUserPrompt" failed with error: no such alert - No dialog is showing

Attempting to use the browser.on('dialog') handler as described in the documentation does not effect this outcome as far as I can tell https://webdriver.io/docs/api/dialog/. When running tests in our product - removing the beforeunload event listener completely prevents this error from occurring and the test proceeds as expected.

This dialog does disappear before the failure occurs - but I manually reproduced the steps to invoke it for the sake of screenshotting the exact dialog box it's failing to handle

Image

What is your expected behavior?

I expect to be able to either accept or dismiss this dialog using the browser.on('dialog') handler as described in the documentation to allow the test to proceed https://webdriver.io/docs/api/dialog/.

How to reproduce the bug.

I have spun up a repository that reproduces this issue here https://github.com/alexanderjkremer/dialog_failure_example

Relevant log output

alexander.kremer dialog_failure_example % yarn wdio      

Execution of 1 workers started at 2025-10-21T15:20:03.596Z

2025-10-21T15:20:03.611Z INFO @wdio/cli:launcher: Run onPrepare hook
2025-10-21T15:20:03.612Z INFO @wdio/utils: Setting up browser driver for: chrome@stable
2025-10-21T15:20:03.612Z INFO @wdio/utils: Setting up browser binaries for: chrome@stable
2025-10-21T15:20:03.830Z INFO webdriver: Using Chromedriver v141.0.7390.108 from cache directory /var/folders/v1/7l2spjj90xbdpv3q6fm6r5040000gq/T
2025-10-21T15:20:03.831Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2025-10-21T15:20:03.832Z INFO @wdio/xvfb: XvfbManager.init() called
2025-10-21T15:20:03.832Z INFO @wdio/xvfb: Xvfb not needed on current platform
2025-10-21T15:20:03.832Z INFO @wdio/local-runner: Start worker 0-0 with arg: run ./wdio.conf.ts
2025-10-21T15:20:03.856Z INFO @wdio/xvfb:ProcessFactory: xvfb-run not found, falling back to regular fork
2025-10-21T15:20:03.857Z INFO @wdio/xvfb:ProcessFactory: ProcessFactory: shouldRun=false, isAvailable=false
2025-10-21T15:20:03.857Z INFO @wdio/xvfb:ProcessFactory: Creating worker process with regular fork
[0-0] 2025-10-21T15:20:04.277Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - file:///test/specs/test.e2e.ts
[0-0] 2025-10-21T15:20:04.321Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2025-10-21T15:20:04.426Z INFO webdriver: Using Chromedriver v141.0.7390.108 from cache directory /var/folders/v1/7l2spjj90xbdpv3q6fm6r5040000gq/T
[0-0] 2025-10-21T15:20:04.444Z INFO chromedriver: Starting ChromeDriver 141.0.7390.108 (79abd1fdb9fb181f228c16000a90806ceaa09fc5-refs/branch-heads/7390@{#2245}) on port 58200
[0-0] 2025-10-21T15:20:04.445Z INFO chromedriver: Remote connections are allowed by an allowlist (0.0.0.0).
[0-0] 2025-10-21T15:20:04.445Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[0-0] 2025-10-21T15:20:04.459Z INFO chromedriver: ChromeDriver was started successfully on port 58200.
[0-0] 2025-10-21T15:20:04.536Z INFO @wdio/utils: Started Chromedriver v141.0.7390.108 with params --port=58200 --allowed-origins=* --allowed-ips=0.0.0.0 in 147ms on port 58200
[0-0] 2025-10-21T15:20:04.538Z INFO webdriver: [POST] http://localhost:58200/session
[0-0] 2025-10-21T15:20:05.859Z INFO webdriver: Register BiDi handler for session with id 19ec59fc4afd46accbd03da0e9601336
[0-0] 2025-10-21T15:20:05.859Z INFO webdriver: Connecting to webSocketUrl ws://127.0.0.1:58200/session/19ec59fc4afd46accbd03da0e9601336
[0-0] 2025-10-21T15:20:05.865Z INFO webdriver: Connected to Bidi protocol at ws://127.0.0.1:58200/session/19ec59fc4afd46accbd03da0e9601336
[0-0] 2025-10-21T15:20:05.865Z INFO webdriver: Connected to WebDriver Bidi interface at ws://127.0.0.1:58200/session/19ec59fc4afd46accbd03da0e9601336
[0-0] 2025-10-21T15:20:05.865Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2025-10-21T15:20:05.866Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
[0-0] 2025-10-21T15:20:05.866Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.contextCreated"]}
[0-0] 2025-10-21T15:20:05.867Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["log.entryAdded","browsingContext.navigationStarted"]}
[0-0] 2025-10-21T15:20:05.867Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[1319 bytes]>, contexts: undefined }
[0-0] 2025-10-21T15:20:05.867Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted","browsingContext.fragmentNavigated","network.responseCompleted","network.beforeRequestSent","network.fetchError"]}
[0-0] 2025-10-21T15:20:05.867Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.userPromptOpened"]}
[0-0] 2025-10-21T15:20:05.867Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted"]}
[0-0] 2025-10-21T15:20:05.867Z INFO webdriver: [GET] http://localhost:58200/session/19ec59fc4afd46accbd03da0e9601336/window
[0-0] 2025-10-21T15:20:05.870Z INFO webdriver: RESULT 529C6387D65EE4DBB4CA22DB512DB70E
[0-0] 2025-10-21T15:20:05.872Z INFO webdriver: BIDI RESULT {"id":1,"result":{"contexts":[{"children":[],"clientWindow":"869707164","context":"529C6387D65EE4DBB4CA22DB512DB70E","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"}]},"type":"success"}
[0-0] 2025-10-21T15:20:05.872Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id 529C6387D65EE4DBB4CA22DB512DB70E
[0-0] 2025-10-21T15:20:05.872Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[443 bytes] webdriverioPolyfill>","target":{"children":[],"clientWindow":"869707164","context":"529C6387D65EE4DBB4CA22DB512DB70E","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"},"awaitPromise":false}
[0-0] 2025-10-21T15:20:05.872Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[443 bytes]>, contexts: ["529C6387D65EE4DBB4CA22DB512DB70E"] }
[0-0] 2025-10-21T15:20:05.873Z INFO webdriver: BIDI RESULT {"id":2,"result":{"subscription":"b3de7bec-de9e-44df-8f52-231cc3cd0f0a"},"type":"success"}
[0-0] 2025-10-21T15:20:05.873Z INFO webdriver: BIDI RESULT {"id":3,"result":{"subscription":"fe87d2dc-e0b3-46db-96c7-2c57121e9bd5"},"type":"success"}
[0-0] 2025-10-21T15:20:05.874Z INFO webdriver: BIDI RESULT {"id":4,"result":{"script":"256c6572-1fba-4d01-9cbe-f60073c82a73"},"type":"success"}
[0-0] 2025-10-21T15:20:05.874Z INFO webdriver: BIDI RESULT {"id":5,"result":{"subscription":"3e14d202-495d-4260-abd9-623be2cdab77"},"type":"success"}
[0-0] 2025-10-21T15:20:05.874Z INFO webdriver: BIDI RESULT {"id":6,"result":{"subscription":"08dbaa48-62c8-40a3-ae73-6b55cbd23151"},"type":"success"}
[0-0] 2025-10-21T15:20:05.875Z INFO webdriver: BIDI RESULT {"id":7,"result":{"subscription":"9eeafb81-ff61-42bd-bc8a-aac4530041f5"},"type":"success"}
[0-0] 2025-10-21T15:20:05.884Z INFO webdriver: BIDI RESULT {"id":8,"result":{"realm":"5711475410991168972.1535680629721876780","result":{"type":"undefined"},"type":"success"},"type":"success"}
[0-0] 2025-10-21T15:20:05.884Z INFO webdriver: BIDI RESULT {"id":9,"result":{"script":"bd071719-5a51-4d39-81de-8c39ee56a958"},"type":"success"}
[0-0] 2025-10-21T15:20:05.889Z INFO webdriver: COMMAND navigateTo("file:///Users/alexander.kremer/Documents/dialog_failure_example/index.html")
[0-0] 2025-10-21T15:20:05.889Z INFO webdriver: [POST] http://localhost:58200/session/19ec59fc4afd46accbd03da0e9601336/url
[0-0] 2025-10-21T15:20:05.889Z INFO webdriver: DATA {
[0-0]   url: 'file:///Users/alexander.kremer/Documents/dialog_failure_example/index.html'
[0-0] }
[0-0] 2025-10-21T15:20:05.971Z INFO webdriver: RESULT null
[0-0] 2025-10-21T15:20:05.972Z INFO webdriver: BIDI COMMAND browsingContext.locateNodes {"locator":{"type":"css","value":"input"},"context":"529C6387D65EE4DBB4CA22DB512DB70E"}
[0-0] 2025-10-21T15:20:05.978Z INFO webdriver: BIDI RESULT {"id":10,"result":{"nodes":[{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2","type":"node","value":{"attributes":{"id":"name","name":"name","type":"text"},"childNodeCount":0,"localName":"input","namespaceURI":"http://www.w3.org/1999/xhtml","nodeType":1,"shadowRoot":{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.4","type":"node","value":{"childNodeCount":1,"mode":"closed","nodeType":11}}}}]},"type":"success"}
[0-0] 2025-10-21T15:20:05.982Z INFO webdriver: BIDI COMMAND browsingContext.locateNodes {"locator":{"type":"css","value":"input"},"context":"529C6387D65EE4DBB4CA22DB512DB70E"}
[0-0] 2025-10-21T15:20:05.987Z INFO webdriver: BIDI RESULT {"id":11,"result":{"nodes":[{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2","type":"node","value":{"attributes":{"id":"name","name":"name","type":"text"},"childNodeCount":0,"localName":"input","namespaceURI":"http://www.w3.org/1999/xhtml","nodeType":1,"shadowRoot":{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.4","type":"node","value":{"childNodeCount":1,"mode":"closed","nodeType":11}}}}]},"type":"success"}
[0-0] 2025-10-21T15:20:05.989Z INFO webdriver: BIDI COMMAND browsingContext.locateNodes {"locator":{"type":"css","value":"input"},"context":"529C6387D65EE4DBB4CA22DB512DB70E"}
[0-0] 2025-10-21T15:20:05.991Z INFO webdriver: BIDI RESULT {"id":12,"result":{"nodes":[{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2","type":"node","value":{"attributes":{"id":"name","name":"name","type":"text"},"childNodeCount":0,"localName":"input","namespaceURI":"http://www.w3.org/1999/xhtml","nodeType":1,"shadowRoot":{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.4","type":"node","value":{"childNodeCount":1,"mode":"closed","nodeType":11}}}}]},"type":"success"}
[0-0] 2025-10-21T15:20:05.992Z INFO webdriver: BIDI COMMAND browsingContext.locateNodes {"locator":{"type":"css","value":"input"},"context":"529C6387D65EE4DBB4CA22DB512DB70E"}
[0-0] 2025-10-21T15:20:05.998Z INFO webdriver: BIDI RESULT {"id":13,"result":{"nodes":[{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2","type":"node","value":{"attributes":{"id":"name","name":"name","type":"text"},"childNodeCount":0,"localName":"input","namespaceURI":"http://www.w3.org/1999/xhtml","nodeType":1,"shadowRoot":{"sharedId":"f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.4","type":"node","value":{"childNodeCount":1,"mode":"closed","nodeType":11}}}}]},"type":"success"}
[0-0] 2025-10-21T15:20:06.000Z INFO webdriver: COMMAND elementClear("f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2")
[0-0] 2025-10-21T15:20:06.000Z INFO webdriver: [POST] http://localhost:58200/session/19ec59fc4afd46accbd03da0e9601336/element/f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2/clear
[0-0] 2025-10-21T15:20:06.026Z INFO webdriver: RESULT null
[0-0] 2025-10-21T15:20:06.026Z INFO webdriver: COMMAND elementSendKeys("f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2", "a")
[0-0] 2025-10-21T15:20:06.026Z INFO webdriver: [POST] http://localhost:58200/session/19ec59fc4afd46accbd03da0e9601336/element/f.529C6387D65EE4DBB4CA22DB512DB70E.d.6B5671D786BEB59C892B800312FE737A.e.2/value
[0-0] 2025-10-21T15:20:06.026Z INFO webdriver: DATA { text: 'a' }
[0-0] 2025-10-21T15:20:06.091Z INFO webdriver: RESULT null
[0-0] 2025-10-21T15:20:06.092Z INFO webdriver: BIDI COMMAND browsingContext.navigate {"context":"529C6387D65EE4DBB4CA22DB512DB70E","url":"https://google.com","wait":"complete"}
[0-0] 2025-10-21T15:20:06.133Z INFO webdriver: BIDI COMMAND browsingContext.handleUserPrompt {"accept":false,"context":"529C6387D65EE4DBB4CA22DB512DB70E"}
[0-0] 2025-10-21T15:20:06.139Z INFO webdriver: BIDI RESULT {"error":"no such alert","id":15,"message":"No dialog is showing","type":"error"}
[0-0] 2025-10-21T15:20:08.204Z INFO webdriver: BIDI RESULT {"id":14,"result":{"navigation":"6c2ed636-ec7a-4b90-80d3-3f0df45a73a3","url":"https://www.google.com/?zx=1761060006632&no_sw_cr=1"},"type":"success"}
[0-0] Error in "My Login application should change URL to Google and fail on "Leave this site" dialog"
Unhandled promise rejection: Error: WebDriver Bidi command "browsingContext.handleUserPrompt" failed with error: no such alert - No dialog is showing
[0-0] 2025-10-21T15:20:08.206Z INFO webdriver: COMMAND deleteSession()
[0-0] 2025-10-21T15:20:08.207Z INFO webdriver: [DELETE] http://localhost:58200/session/19ec59fc4afd46accbd03da0e9601336
[0-0] 2025-10-21T15:20:08.267Z INFO webdriver: RESULT null
[0-0] 2025-10-21T15:20:08.267Z INFO webdriver: Close Bidi connection to ws://127.0.0.1:58200/session/19ec59fc4afd46accbd03da0e9601336
[0-0] 2025-10-21T15:20:08.267Z INFO webdriver: Kill driver process with PID 71675
[0-0] FAILED in chrome - file:///test/specs/test.e2e.ts
2025-10-21T15:20:08.390Z INFO @wdio/cli:launcher: Run onWorkerEnd hook

 "spec" Reporter:
------------------------------------------------------------------
[chrome 141.0.7390.108 mac #0-0] Running: chrome (v141.0.7390.108) on mac
[chrome 141.0.7390.108 mac #0-0] Session ID: 19ec59fc4afd46accbd03da0e9601336
[chrome 141.0.7390.108 mac #0-0]
[chrome 141.0.7390.108 mac #0-0] » test/specs/test.e2e.ts
[chrome 141.0.7390.108 mac #0-0] My Login application
[chrome 141.0.7390.108 mac #0-0]     should navigate to index.html and modify the input
[chrome 141.0.7390.108 mac #0-0]     should change URL to Google and fail on "Leave this site" dialog
[chrome 141.0.7390.108 mac #0-0]
[chrome 141.0.7390.108 mac #0-0] 1 passing (2.3s)
[chrome 141.0.7390.108 mac #0-0] 1 failing
[chrome 141.0.7390.108 mac #0-0]
[chrome 141.0.7390.108 mac #0-0] 1) My Login application should change URL to Google and fail on "Leave this site" dialog
[chrome 141.0.7390.108 mac #0-0] Unhandled promise rejection: Error: WebDriver Bidi command "browsingContext.handleUserPrompt" failed with error: no such alert - No dialog is showing


Spec Files:	 0 passed, 1 failed, 1 total (100% completed) in 00:00:04  

2025-10-21T15:20:08.390Z INFO @wdio/local-runner: Shutting down spawned worker
2025-10-21T15:20:08.643Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2025-10-21T15:20:08.643Z INFO @wdio/local-runner: shutting down
2025-10-21T15:20:08.644Z INFO @wdio/cli:launcher: Run onComplete hook

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions