Skip to content

Node.js crash (Uncaught Exception) during Take Screenshot on failure when execution context is destroyed #4956

@ElionSylwin

Description

@ElionSylwin

Description:
When a test fails and the library attempts to perform automatic failure actions (specifically Take Screenshot which involves element highlighting), the Node.js process crashes with an uncaught exception if the browser's execution context is destroyed (e.g., due to navigation or page close) at the exact same moment. This prevents the test suite from completing and fails the entire process instead of just the individual test case.

Steps to reproduce the behavior:

  1. Run a test that fails (e.g., a Wait For Element State timeout).
  2. Ensure the application is in a state where it might navigate or close the page immediately after the failure.
  3. The library triggers Take Screenshot as the on_failure keyword.
  4. The library attempts to highlight the failed selector, throwing Uncaught Exception crashing node.js

Expected behavior:
The library should catch Playwright errors during the "on failure" screenshot/highlight phase. If the execution context is destroyed, it should fail the screenshot without crashing the Node.js server.

Actual behavior:
The Node.js wrapper throws an uncaught exception:
Error: locator.highlight: Execution context was destroyed, most likely because of a navigation
This triggers node:internal/process/promises:394 triggerUncaughtException(err, true) and the process exits.

Desktop:

  • OS: Windows
  • Browser Chromium
  • Version 19.10.1

Additional context
Reason behind my belief that highlighting is the cause of this issue is that when highlighting is "disabled" using highlight_selector=${EMPTY}, this issue is no longer present, a screenshot upon failure is taken and test suite progress normally.

playwright log snippet:
{"level":30,"time":"2026-06-10T09:21:45.964Z","msg":"Start of node method takeScreenshot"}
node:internal/process/promises:394
triggerUncaughtException(err, true /* fromPromise */);
^

locator.highlight: Execution context was destroyed, most likely because of a navigation
at highlightAll (C:\snapshot\robotframework-browser\Browser\wrapper\index.js:7924:18)
at async highlightElements (C:\snapshot\robotframework-browser\Browser\wrapper\index.js:7900:17)
at async PlaywrightServer.highlightElements (C:\snapshot\robotframework-browser\Browser\wrapper\index.js:9702:26) {
name: 'Error'
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions