ckerr

#54725: test: wait for the page to be focused before clipboard and paste specs

Merged
Created: Oct 7, 2026, 3:10:08 PM
Merged: Oct 8, 2026, 8:53:08 AM
6 comments
Target: main

Description of Change

Make the clipboard, paste and pointer-lock specs wait until the page itself reports focus.

These specs either waited for the webContents 'focus' event or didn't wait at all before calling paste().
That event comes from the browser process, and the page can still report document.hasFocus() === false right after it.
In that window, navigator.clipboard rejects with "Document is not focused." and paste() can be dropped.
Downstream CI hits this on 42-x-y, 43-x-y and 44-x-y: expected 'Document is not focused.' to include 'Read permission denied.' in the clipboard permission spec, and "File System API … denies permission when trying to create a writable file handle".

This change:

  • Adds a focusWebContents() helper to spec/lib/spec-helpers.ts.
    It focuses the contents, waits for 'focus', and then waits until the page reports document.hasFocus(), requesting focus again while it waits.
  • Replaces the six copies of the isFocused() / once('focus') / focus() block with it: navigator.clipboard.read and .write, paste execCommand, pointer lock, user activation, and the File System Access permission scope pasteHandle.
  • Calls it before each paste() in the File System API specs, which previously called focus() and paste() with no wait.
  • In the done-style File System specs, passes any failure while preparing the paste to done() instead of letting it escape the 'did-finish-load' listener.

The other 'focus' waits in api-web-contents.spec.ts test the event itself, so they stay as they are.
Only test code changes.

Validation

Ran on a local Linux testing build of main under Xvfb:

  • e test --files spec/chromium.spec.ts -g "File System API|File System Access permission scope|navigator.clipboard|paste execCommand|pointer lock permission request|user activation": 28 passed, and 4 of 4 runs passed.
  • script/lint.js --js and tsc -p tsconfig.spec.json pass.

The failures this targets come from downstream CI timing and haven't been reproduced locally.

🤖 Generated with Claude Code

Checklist

Release Notes

Notes: none

Backports

42-x-y
Pending
Waiting for a manual backport
43-x-y
Pending
Waiting for a manual backport
44-x-y
In-flight
PR Number
#54767
Waiting to be merged
45-x-y
Merged
PR Number
#54759
Merged At
Oct 8, 2026, 11:00:59 AM
Released In
v45.0.0-beta.1
Release Date
Oct 8, 2026, 7:07:44 PM

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron