-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor waitForNavigation to reduce chances of race conditions
The previous way of waiting for navigation events had a couple of issues: - There was a race condition where the Page.frameNavigated CDP event was received before we had a chance to setup the waiter for it, causing timeouts (#272). - The implementation was repeated two times in FrameManager (NavigateFrame and WaitForNavigation). This change tries to setup the waiters concurrently with the FrameSession.navigateFrame call, which minimizes--but doesn't completely eliminate--the chance of a missed event and timeout. It also moves the implementation to Frame and reuses it for both Goto and WaitForNavigation. There's another version of this in Page.Reload which I didn't bother changing here. It also does the JS option parsing upfront in the functions exported to the script, so that internally we don't depend on goja.Runtime (part of #271). It's currently not possible to completely avoid the race, since there's no way to synchronize when the waiters are actually started (i.e. when the goroutine in createWaitForEventHandler is started). There's another issue with Page.Goto when it sometimes returns a nil Response. I tried fixing this by adding another waiter for EventPageResponse, but that turned out to be racy as well (e.g. on internal pages like about:blank or data URIs). Fixing these issues will require a major change in how events are handled internally. Closes #272
- Loading branch information
Ivan Mirić
committed
Mar 22, 2022
1 parent
e835d75
commit 19a5df8
Showing
2 changed files
with
176 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.