Skip to content

[Bug]: Tracing marks every page as user-activated (navigator.userActivation.hasBeenActive is true with no gesture) #44119

Open

Description

Note

🤖 Claude Opus 5.5 opening this issue on behalf of Will

Version

1.65.1 (also 1.66.0-alpha-2026-11-14)

Steps to reproduce

Minimal reproduction: https://github.com/ceolinwill/playwright-tracing-user-activation

git clone https://github.com/ceolinwill/playwright-tracing-user-activation
cd playwright-tracing-user-activation
npm install
npx playwright install chromium
npm run repro

The script serves one static HTML page, opens it in two fresh contexts (one with context.tracing.start({ snapshots: true }), one without), and reads navigator.userActivation.hasBeenActive through a CDP session with userGesture: false, since page.evaluate itself grants activation.

Output:

without tracing: navigator.userActivation.hasBeenActive = false
with tracing: navigator.userActivation.hasBeenActive = true
BUG: tracing marked a page nobody interacted with as user-activated.

Expected behavior

Recording a trace doesn't change the page: navigator.userActivation.hasBeenActive stays false until the test acts on the page, as it does without tracing.

Actual behavior

With tracing on, a page nobody clicked reports hasBeenActive === true right after page.goto(). Any app code that waits for the user's first gesture (sending something only after the first interaction, unmuting audio, opening a popup) behaves differently while a trace is recorded, so a test that checks the page wasn't activated passes without --trace and fails with it (trace: 'retain-on-failure' or 'on' in the config, or --trace on the command line).

Where it comes from: starting tracing with snapshots starts a HarTracer (packages/playwright-core/src/server/trace/recorder/tracing.ts). On the main frame's domcontentloaded and load, HarTracer._onDOMContentLoaded and _onLoad (packages/playwright-core/src/server/har/harTracer.ts) read the page title and timings with page.mainFrame().evaluateExpression(...) in the utility world. On Chromium every such evaluation goes through CRExecutionContext.evaluateWithArguments, which sends Runtime.callFunctionOn with userGesture: true (packages/playwright-core/src/server/chromium/crExecutionContext.ts). User activation is per frame, not per world, so these internal reads activate the page. Running the script with DEBUG=pw:protocol shows both calls with "userGesture":true.

Additional context

A possible fix: run these internal reads without a user gesture (for example with rawEvaluateJSON, which the snapshotter already uses for its captures), or pass userGesture: false for evaluations Playwright makes on its own behalf.

In our app's E2E suite, a test that checks a reload doesn't activate the page failed 10 of 10 times with tracing on and passed 10 of 10 with it off. We now turn tracing off for that one file with test.use({ trace: 'off' }).

Environment

- Operating System: macOS 27.2.1 (arm64)
- Browser: Chromium 159.0.8154.6
- Node.js: 24.22.0
- npm: 11.19.1
- Playwright: 1.65.1 and 1.66.0-alpha-2026-11-14

Activity

  1. microsoft-playwright-automation commented on Nov 16, 2026

    @microsoft-playwright-automation
  2. microsoft-playwright-automation commented on Nov 16, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot and I reproduced this on macOS.

    Reproduced on 1.66.0-next (826ce42b8664ea940424e77ce51f1cdf96dcd37f). The HAR recorder's title and timing reads grant user activation. Changing both reads to raw evaluation in the utility world fixes the reported Chromium case and also fixes WebKit.

    Firefox still reports activation: its browser-side Runtime.evaluate unconditionally grants a user gesture, including for raw evaluations. This proposal does not change Firefox's protocol.

    Condensed regression

    The existing tracing test is extended with this check before its first click. A mouse move reads the value without granting activation; page.evaluate would grant activation itself.

    await page.addInitScript(() => {
      document.addEventListener('mousemove', () =>
        console.log(`user-activation:${navigator.userActivation.hasBeenActive}`),
      { once: true });
    });
    await context.tracing.start({ snapshots: true });
    await page.goto(server.PREFIX + '/input/button.html');
    const activation = page.waitForEvent('console',
        message => message.text().startsWith('user-activation:'));
    await page.mouse.move(10, 10);
    expect((await activation).text()).toBe('user-activation:false');
    What I ran

    All runs used macOS, headless browsers, and the checkout above.

    Browser Snapshots enabled, before fix Snapshots enabled, after fix
    Chromium 159.0.8154.6 true false
    WebKit 27.2 true false
    Firefox 159.0 true true

    A separate data-page check returned false in every browser with tracing off or with snapshots disabled. The activation assertion covers Chromium and WebKit; the existing tracing assertions still run in Firefox.

    The build and npm run flint passed. The full tracing.spec.ts, har.spec.ts, and browsercontext-har.spec.ts suites passed across all three browsers: 431 passed, 7 skipped, no retries.

    Draft PR: #44152

    Triaged on macOS by the Playwright bot - agent run

  3. dcrousso commented on Nov 17, 2026

    @dcrousso
    Contributor
  4. microsoft-playwright-automation commented on Nov 17, 2026

    @microsoft-playwright-automation
  5. microsoft-playwright-automation commented on Nov 17, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot. The Firefox browser report is prepared for filing, as requested in the review of #44152. It includes the condensed regression and the earlier browser-side fix experiment. No second Playwright PR is proposed.

    Blocked-by: https://github.com/microsoft/playwright-browsers/issues/2733

    Triaged on macOS by the Playwright bot - agent run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions