Skip to content

fix(errors): treat detached-frame and early-main-frame as retryable#846

Merged
Kikobeats merged 1 commit into
masterfrom
fix/frame-lifecycle-retry
Jul 20, 2026
Merged

fix(errors): treat detached-frame and early-main-frame as retryable#846
Kikobeats merged 1 commit into
masterfrom
fix/frame-lifecycle-retry

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Jul 20, 2026

Copy link
Copy Markdown
Member

Problem

captureWithNavigationRetry (which wraps page.pdf() / page.screenshot()) and waitForReady only wait-for-navigation-and-retry when isContextDestroyed returns true. Two frame-lifecycle races on production 3.42.8 are not recognized, so they fail the capture immediately:

Execution context is not available in detached frame or worker "<url>"   6 requests / 24h
Requesting main frame too early!                                          2 requests / 24h

Sample (d53acca8, app.oviond.com — a SPA that navigates to a sub-route mid-print):

pdf chunk pages=4 ... duration=19.6s
pdf render n=1 pages=4 duration=8.1s
chunk:failed message="Execution context is not available in detached frame or worker \"https://app.oviond.com/pdf/.../project/...\""
parallel:fallback message="Execution context is not available in detached frame ..."

Fix

Add both strings to isContextDestroyed:

  • Execution context is not available in detached frame — Chrome's other phrasing of a frame detaching mid-operation. Semantically identical to the already-matched Attempted to use detached Frame; the retry (wait for navigation to settle, re-run on the new frame) is exactly right.
  • Requesting main frame too early — the inverse race: the operation ran before the page's main frame attached. The frame arrives once navigation commits, so a settle-and-retry resolves it.

The retry is bounded by timeouts.action, so a genuinely broken page that never navigates falls through the same as today — just after a short wait instead of instantly.

Confidence

Not equal between the two, stated plainly:

  • detached-frame: high. 6 occurrences, real SaaS pages, same class as an existing matched pattern.
  • main-frame-too-early: lower. 2 occurrences, both on pages that also logged empty response / prerender:error (may never navigate). Included because it is a genuine transient lifecycle race and the retry cost is bounded, but it may just convert a fast fail into a short-delayed fail on broken pages rather than rescue them.

Tests: 9 pass, isContextDestroyed extended with both production strings.

🤖 Generated with Claude Code


Note

Low Risk
Small, localized change to error-string classification in the errors package; bounded retry behavior already exists for similar patterns.

Overview
Extends isContextDestroyed so two production Chrome frame-lifecycle errors are treated like existing navigation/context teardown races and flow through ensureError as contextDisconnected (enabling settle-and-retry in PDF/screenshot paths instead of immediate failure).

New matches: Execution context is not available in detached frame (detached frame mid-operation) and Requesting main frame too early (main frame not attached yet). Comments on the helper are updated to describe both “torn down mid-flight” and “not yet attached” cases.

Tests add positive cases for both production message strings.

Reviewed by Cursor Bugbot for commit 7235937. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of browser errors caused by detached frames, unavailable execution contexts, and early main-frame requests.
    • These conditions are now more reliably identified as temporary context disconnections.

`captureWithNavigationRetry` (wrapping page.pdf/screenshot) and `waitForReady`
only wait-and-retry when `isContextDestroyed` matches. Two frame-lifecycle
races on production 3.42.8 slipped through and failed the capture outright:

  Execution context is not available in detached frame or worker "<url>"   (6/24h)
  Requesting main frame too early!                                          (2/24h)

The first is Chrome's other phrasing of a frame detaching mid-operation — the
same condition as the already-matched "Attempted to use detached Frame", seen
on SPAs (app.oviond.com) that client-navigate to a sub-route while a print
targeting the old frame is in flight. The second is the inverse: an operation
ran before the page's main frame attached.

Both resolve once navigation settles, which is exactly what the retry does; a
page that never navigates falls through when the bounded retry budget
(timeouts.action) ends, same as today, just after a short wait.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c2d1f647-1df8-44cd-9e96-b50cbd107545

📥 Commits

Reviewing files that changed from the base of the PR and between 6c4a44b and 7235937.

📒 Files selected for processing (2)
  • packages/errors/index.js
  • packages/errors/test/index.js

📝 Walkthrough

Walkthrough

isContextDestroyed now recognizes additional Chrome/DevTools errors for detached or unavailable frames, including early main-frame requests. Tests cover the new error messages, and its documentation reflects frame teardown and attachment races.

Changes

Context destruction detection

Layer / File(s) Summary
Expand context detection and coverage
packages/errors/index.js, packages/errors/test/index.js
The helper matches additional detached-frame and early-main-frame messages, with tests covering both new positive cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: making detached-frame and early-main-frame errors retryable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/frame-lifecycle-retry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Kikobeats
Kikobeats merged commit 3d529b1 into master Jul 20, 2026
12 of 13 checks passed
@Kikobeats
Kikobeats deleted the fix/frame-lifecycle-retry branch July 20, 2026 20:56
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.

1 participant