Skip to content

takeSnapshot throws "Execution context was destroyed" due to about:blank iframes created by its own archiving process #307

@mbouchardC3

Description

@mbouchardC3

Describe the bug
Calling takeSnapshot mid-test intermittently throws the following error:
Error: proxy.evaluate: Execution context was destroyed, most likely because of a navigation.
at takeSnapshot (.../node_modules/@chromatic-com/playwright/dist/index.js:18:49598)
By attaching frameattached and framenavigated listeners to the page, we confirmed that takeSnapshot itself is creating about:blank iframes as part of its DOM archiving process. The navigation events fired by those iframes destroy the execution context that takeSnapshot's own page.evaluate() is running in, causing it to crash itself. The main frame never navigates — the issue is entirely self-inflicted by takeSnapshot's internals.
Additionally, the number of iframes created grows with each retry (1 on the first call, 2 on the second, 3 on the third, etc.), meaning retrying makes the problem progressively worse.

To Reproduce

  1. Set up a Playwright test using @chromatic-com/playwright
  2. Navigate to a page that has any background activity (polling, websockets, periodic re-renders, etc.)
  3. Perform an action that triggers a data reload (e.g. applying a filter on a grid)
  4. Call takeSnapshot(page, 'my-snapshot', testInfo) immediately after
  5. See the error above

Expected behavior
takeSnapshot should complete successfully regardless of the about:blank iframes it creates internally. Its own iframe lifecycle should not be able to destroy its own page.evaluate() execution context.

Screenshots
Logs confirming the iframes are created by takeSnapshot itself, not the application:
[FRAME] Existing frame 0: https://
[SNAPSHOT] About to take snapshot at 1775770090272
[FRAME ATTACHED] at 1775770090300
[NAV] Frame navigated - isMain: false, url: about:blank at 1775770090301
[FRAME ATTACHED] at 1775770090308
[NAV] Frame navigated - isMain: false, url: about:blank at 1775770090309

[SNAPSHOT] About to take snapshot at 1775770093321
[FRAME ATTACHED] at 1775770093335
[FRAME ATTACHED] at 1775770093335
[NAV] Frame navigated - isMain: false, url: about:blank at 1775770093336
[NAV] Frame navigated - isMain: false, url: about:blank at 1775770093336

Additional context
@chromatic-com/playwright: 0.12.8
@playwright/test: 1.59.1
Browser: Chromium
This issue does not occur with percySnapshot, which uses page.screenshot() and has no execution context dependency
Attempted workarounds (route blocking, CDP lifecycle events, retries) all fail because the context is destroyed by takeSnapshot's own iframe creation, not by anything the application does

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions