Minimal reproduction of a Playwright issue where navigation waiting hangs indefinitely in Electron apps using separate WebContentsView instances with navigation interception.
In Proton Mail Desktop, different sections (Mail, Calendar, Account) are completely separate WebContentsView instances. When navigating between them:
- User clicks a link to navigate (Mail → Account)
- Electron intercepts the
will-navigateevent - Electron prevents the navigation with
event.preventDefault() - Electron switches views with
mainWindow.setContentView(newView) - The original view never navigates - no navigation event fires
- Playwright hangs waiting for that navigation event that never comes
- macOS (developed for macOS, can be adapted to other OS)
- Node v22, npm
# From the root directory
npm run install-all # Installs app dependencies
npm run playwright:install # Playwright deps
npm run build:electron # Package the electron app (required for Playwright)
npm run dev # Run the development web serverWithout the PLAYWRIGHT_SKIP_NAVIGATION_CHECK environment variable (tests will timeout/hang):
npm run test:electronWatch for this error in the last test i.e. should navigate Mail → Account → Mail → Account [INDEFINITE WAIT FOR NAVIGATION]:
Error: Timed out 5000ms waiting for expect(locator).toContainText(expected)
Received string: ""
Call log:
- waiting for navigation to finish...
With the environment variable set (tests pass):
npm run test:electron:skipelectron-app/main.js (lines 213-236):
webContents.on('will-navigate', (event, url) => {
if (isNavigatingToDifferentView) {
event.preventDefault() // Block navigation
switchView(targetView) // Switch view instead
}
})The navigation is intercepted at the Electron level, so the current view never fires a navigation event.
Each view is a completely separate WebContentsView:
views.mail = new WebContentsView(config)
views.account = new WebContentsView(config)They are not different pages in the same webview. When Playwright tests Mail and clicks to navigate to Account:
- Playwright waits for navigation in the Mail webview
- But Mail never navigates (it's intercepted)
- Account is displayed instead (a different webview)
- Navigating back to Mail view, and looking up another element causes Playwright to hang indefinitely
should navigate Mail → Account → Mail → Account [INDEFINITE WAIT FOR NAVIGATION]
This test demonstrates the hang.
- Open up the main page (Mail view)
- Navigate to Account
- Navigate from Account back to Mail view
- Try to find an element on Mail View
- Hang indefinitely:
waiting for navigation to finish...
The only viable solution I could find is the PLAYWRIGHT_SKIP_NAVIGATION_CHECK environment variable removed as of PR #36283. When set, Playwright skips navigation checks.
I've requested this variable be re-introduced to Playwright (PR #37993).
I'd be more than happy to try an alternative solution if such exists.