Skip to content

Commit

Permalink
fix: support default for BeforeUnload prompt (#2412)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade authored Jul 12, 2024
1 parent f87bb75 commit f24ad85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ export class BrowsingContextImpl {
case BrowsingContext.UserPromptType.Beforeunload:
return (
this.#unhandledPromptBehavior?.beforeUnload ??
this.#unhandledPromptBehavior?.default ??
// In WebDriver Classic spec, `beforeUnload` prompt should be accepted by
// default. Step 4 of "Get the prompt handler" algorithm
// (https://w3c.github.io/webdriver/#dfn-get-the-prompt-handler):
Expand Down
10 changes: 10 additions & 0 deletions tests/browsing_context/test_user_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ async def test_browsingContext_beforeUnloadPromptOpened_capabilityRespected(
if 'beforeUnload' in capabilities['unhandledPromptBehavior']:
expected_handler = capabilities['unhandledPromptBehavior'][
'beforeUnload']
elif 'default' in capabilities['unhandledPromptBehavior']:
expected_handler = capabilities['unhandledPromptBehavior'][
'default']
if isinstance(capabilities['unhandledPromptBehavior'], str):
if capabilities[
'unhandledPromptBehavior'] == 'dismiss' or capabilities[
'unhandledPromptBehavior'] == 'dismiss and notify':
expected_handler = 'dismiss'
elif capabilities['unhandledPromptBehavior'] == 'ignore':
expected_handler = 'ignore'

resp = await read_JSON_message(websocket)
assert resp == {
Expand Down

0 comments on commit f24ad85

Please sign in to comment.