Skip to content

fix(screenshotter): race cleanup against progress to honor timeout - #40901

Merged
Simon Knott (Skn0tt) merged 1 commit into
microsoft:mainfrom
Skn0tt:fix-36702
Jun 1, 2026
Merged

Simon Knott (Skn0tt) merged 1 commit into
microsoft:mainfrom
Skn0tt:fix-36702

Conversation

@Skn0tt

Copy link
Copy Markdown
Contributor

Cleanup in screenshotPage / screenshotElement finally blocks was not raced against progress. When the renderer's event loop is blocked, nonStallingEvaluateInExistingContext only races against navigation / open dialogs — not arbitrary timeouts — so cleanup would hang indefinitely and swallow the timeout error.

Fixes #36702

The `finally` blocks in `screenshotPage` and `screenshotElement` awaited
`_restorePageAfterScreenshot()` without racing against `progress`. If
the renderer's event loop was blocked (e.g. busy JS loop),
`nonStallingEvaluateInExistingContext` would hang indefinitely because
it only races against navigation / open dialogs, not against an
arbitrary timeout — swallowing the timeout error and hanging the call.

Wrap both cleanups in `progress.race(...).catch(() => {})`. The
`.catch` is required to avoid masking an in-flight error from the
`try` block with the abort error from the race.

Fixes: microsoft#36702

@dgozman Dmitry Gozman (dgozman) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is a good solution. We'll end up in a situation where we were able to set things up, then we were not able to tear things down, and now the page is kind of broken.

It seems like we were not able to _preparePageForScreenshot() in this case as well though. If so, we don't have to do any cleanup as well. Perhaps that would be a better fix?

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

7116 passed, 1113 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

3 flaky ⚠️ [chromium-library] › library/browsertype-connect.spec.ts:699 › run-server › should record trace with sources `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [chromium-library] › library/video.spec.ts:719 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node20`
⚠️ [webkit-library] › library/browsertype-connect.spec.ts:792 › launchServer › should upload a folder `@webkit-ubuntu-22.04-node20`

42016 passed, 850 skipped


Merge workflow run.

@Skn0tt

Copy link
Copy Markdown
Contributor Author

In this particular test case, the prepare succeeds because of the 10ms timeout until the spin begins. And looking at _preparePageForScreenshot, it throws an error if it doesn't succeed, so I think what you suggest we already implement.

@Skn0tt
Simon Knott (Skn0tt) merged commit 1aa42fa into microsoft:main Jun 1, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: page.screenshot can hang and timeout option doesn't make it timed out

2 participants