Repository navigation
fix(chromium): retry screenshot when page navigates away mid capture - #43721
Closed
Adarsh (jackeddisciple) wants to merge 1 commit into
Closed
Adarsh (jackeddisciple) wants to merge 1 commit into
Adarsh (jackeddisciple) wants to merge 1 commit into
Conversation
Collaborator
|
I am not sure retrying is the right fix. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Chromium,
page.screenshot()can hang until timeout when the main frame commits a new document whilePage.captureScreenshotis in flight. With slightly different timing it throwsProtocol error (Page.captureScreenshot): Not attached to an active pageinstead. This is what makes SS-027 time out in the Java port.Root cause
Page.captureScreenshotasks the widget of the current document to draw a frame (ForceRedraw). If that document is destroyed before it draws, the callback is dropped together with the widget and no response is ever sent. Playwright turns bfcache off, so a document that navigates away is always destroyed. Chromium bug: https://issues.chromium.org/issues/578475983ReadyToCommitNavigation. A capture that lands between that point and the commit fails the active host check withNot attached to an active page.Fix
InternalFrameNavigatedToNewDocument). If the commit wins, drop the old capture and runtakeScreenshotagain, so the layout metrics and the clip come from the new document.Not attached to an active pagethe same way.Page.getLayoutMetricsuntil the navigation finishes, so the next attempt only runs once the new document is in place. The call timeout still applies, so an endless redirect loop ends in a normal timeout.documentRectis no longer mutated, so a retried viewport screenshot uses the scroll position of the new document.Regression test
SS-097 stalls
one-style.css, soone-style.htmlnever renders and the capture stays pending until the page navigates away after 500 ms. On main it times out with the call log ending at "fonts loaded". It is skipped on WebKit, which captures the blocked page right away.Notes
Unable to capture screenshotwhen a capture lands before a fresh document has drawn its first frame. Main does the same and it fails fast, so I left it alone. Retrying it would turn a fast error into a full timeout for pages that never draw.window.outerWidth/outerHeightat the clip size on the headless shell, while the viewport, pixels and input stay correct. The timing window is tiny, and today the same timing can hang.Fixes #43685