#2225

Add origin-scoped clipboard-read permission control (clipboard read fails with NotAllowedError in headless)

Opennsxdavidopened 4d ago

Summary

In a headless session, clipboard read fails with NotAllowedError, because navigator.clipboard.readText() needs the clipboard-read permission. The CLI gives no way to grant that permission for one origin.

Environment

  • agent-browser 0.39.2, headless Chromium
  • Linux

Reproduction

  1. agent-browser open http://localhost:3000/ (any page served from a local origin)
  2. agent-browser clipboard write "hello"
  3. agent-browser clipboard read

Expected: a caller can first grant clipboard-read for http://localhost:3000, and the read then returns hello.

Actual: the read fails with NotAllowedError (from navigator.clipboard.readText()). There is no CLI command that grants clipboard-read scoped to an origin.

Details

  • The daemon's permissions action calls Browser.grantPermissions with only a permissions array. It sets neither origin nor browserContextId, so a grant applies to every origin in the browser instead of the page under test.
  • Callers can't safely send the CDP command themselves. Discovering the endpoint (cdp_url and similar actions) can implicitly launch a browser when none is running.

Proposal

Add an action that works only on an existing browser, for example clipboard permission grant|reset <origin>, which:

  • validates that <origin> matches the active target's origin exactly;
  • calls Browser.setPermission with { name: "clipboard-read" }, setting: "granted" (or "prompt" for reset), that origin, and the target's browserContextId;
  • never launches a browser if none is running.

We patched this locally along those lines and confirmed it with headless Chromium:

  • reads were refused before the grant and allowed after it;
  • a different origin stayed refused;
  • reset restored the refusal.

Activity

0

No activity yet.