I started writing this to ask for help but discovered the answer. I figure it wouldn't hurt to share here.
I have tests that assert that a prompt is shown if a user attempts to navigate away from a page before their data is saved.
After upgrading the test browser from Chromium 104 to Chromium 128, these prompts aren't shown when tests run anymore, and when this Python test code runs then an error occurs:
from selenium.webdriver.common.alert import Alert
Alert(driver).dismiss()
The error is:
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
I wanted to make the beforeunload prompt shown again when running tests so that I can test that a prompt is shown to a user as expected.
I found out how, here it is:
- Drivers released in approximately 2024 and later automatically dismiss beforeunload prompts by default. If the old behavior is needed, enable bidi.
- NOTE: ChromeDriver still dismisses prompts unless options.unhandled_prompt_behavior = 'ignore' is also specified, in addition to enabling bidi (as recently as version 134 or later).
- NOTE: ChromeDriver implemented automatically dismissing beforeunload prompts in approximately version 126 but enabling bidi had no effect on beforeunload prompts until approximately version 133. See the related issue.