feat(web): grant browser permissions from a web target's app.permissions

Merged
KR
18d ago
+220-18

Headless Chromium refuses navigator.clipboard.writeText unless the browser context grants the permission, even after a real click, so an app's "Copy" button can't be tested. web() rejected app.permissions as a device-only key, and the reporter had to write a custom executor calling grantPermissions themselves.

  • A web() target now takes app.permissions. Each grant is applied with context.grantPermissions on every context the attempt opens (packages/web/src/surface.ts), so it holds after app.restart(), app.clearState(), and on CDP or provider-leased browsers.
  • The grant covers every page, on any origin, the same way navigation has no origin allowlist (#290).
  • Names are checked at config load against what Playwright 1.64 grants on the target's browser (packages/web/src/permissions.ts), with a did-you-mean. A provider or connect (Lightpanda included) takes Chromium's names, since the engine drives it over CDP.
  • deny and reset are INVALID_CONFIG on web: Playwright only grants, and Chromium denies every permission a grant leaves out, so neither can mean what it does on a device. Changing permissions mid-test is ENG-1066.
{
  engine: web(),
  app: {
    url: 'http://localhost:3000',
    permissions: { 'clipboard-read': 'grant', 'clipboard-write': 'grant' },
  },
}

Docs: a "Granting browser permissions" section in docs/web.mdx, the per-browser names under permissions in docs/reference/config.mdx, and the skill's setup table.

Issue

Fixes ENG-1038

Verified

Ran it locally: yes

  • Built CLI on a scratch project in apps/testbed: an app whose "Copy link" button calls navigator.clipboard.writeText, and a test that clicks it, expects "Copied", and reads the clipboard back. Same config, with permissions: { 'clipboard-read': 'grant', 'clipboard-write': 'grant' }, run on main and on this branch.
mainthis branch
INVALID_CONFIG: target "web" declares app.permissions, which describes an installed device app; a web() target opens app.url✓ copies the link (200ms)

Without permissions on this branch, the same test fails as the bug report describes:

 FAIL  |web| copy.e2e.ts > copies the link
ASSERTION_FAILED: expect.toBeVisible failed
locator: getByText("Copied")
observed: no node (match count 0)

And a deny is refused at load:

 ERROR  configuration error INVALID_CONFIG (config)
target "web" app.permissions.clipboard-write is deny, but a web() target only grants; leave the permission out instead
  • packages/web/tests/integration/permissions.test.ts covers the grant across restart and context reset, and the refusal without it, in a real browser.
  • Lightpanda implements Browser.grantPermissions (src/server/cdp/domains/browser.zig upstream), so a Lightpanda target with app.permissions does not fail at attempt start. Not run live: no Lightpanda binary on this machine.

Made with Claude Code (Claude Opus 5.5); fresh-context review by Claude Fable 5.