Skip to content

fix(browser): return a real PermissionStatus from the query override - #14684

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-permissions-query-status
Aug 17, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-permissions-query-status

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​210 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​210
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31

ELI5

Sites that ask "tell me when this permission changes" were crashing in our browser. Now they don't.

What Changed

The anti-detection override resolved a bare object literal ({ state, onchange: null }), so the PermissionStatus prototype was gone — no addEventListener, no removeEventListener, no instanceof. Any site doing query(...).then(s => s.addEventListener('change', ...)) threw a TypeError.

It now proxies the genuine status and overrides only state, so the prototype, events and instanceof survive. Where the real implementation rejects a name, it falls back to an EventTarget so listener registration still works instead of throwing.

constructor is deliberately not bound — binding it made constructor.name read "bound PermissionStatus", which is a fresh fingerprinting tell in the very file that exists to remove them. That was caught in live testing and fixed.

Why

Measured against real Chrome 151 on the same Mac and page:

probe real Chrome Orca (before)
permissions.query() returns PermissionStatus plain Object
.addEventListener on it function undefined

Gmail subscribes to notification-permission changes, so this is on the path of the reported in-app Google problems.

Linked Issue

Fixes #14679

Visual Proof

N/A — no visual surface. The change is observable only via the JS API; live measurements are in Testing.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Extended the existing runInNewContext harness in anti-detection.test.ts. The stand-in Permissions now resolves a realistic PermissionStatus (with listener methods), because the previous stand-in could not tell a proxied status from a bare literal. The new test fails against the pre-fix implementation.

Live-verified in a real Electron guest (macOS, https://example.com), after a full restart so the main-process script reloaded:

proto: "PermissionStatus"   state: "prompt"   addEventListener: "function"   listenerOk: true

Gates: 40 files / 638 tests pass · pnpm typecheck clean · oxlint clean · oxfmt --check clean.

Review

No security surface: the change only affects an injected page script's return shape. Cross-platform — pure JS, no platform branches. No IPC, path, or shell handling. Performance: one Proxy per permissions.query() call, which sites call rarely.

Checklist

  • Scope kept tight — does not touch the permission policy itself
  • No max-lines disable or baseline bump

@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 17820db1-14f5-4e52-8545-9ce77b010830

📥 Commits

Reviewing files that changed from the base of the PR and between b6d5972 and ffcf147.

📒 Files selected for processing (2)
  • src/main/browser/anti-detection-permission-status.test.ts
  • src/main/browser/anti-detection.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/browser/anti-detection.ts
  • src/main/browser/anti-detection-permission-status.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The permission query override preserves native PermissionStatus objects and overrides their state values for notification and prompt-based permissions. It creates non-enumerable EventTarget fallbacks when native queries reject or fail. The test suite covers status transitions, native identity and methods, change events, and fallback behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation and tests satisfy issue #14679 by preserving PermissionStatus behavior and listener registration for intercepted permissions.
Out of Scope Changes check ✅ Passed The production change and added tests remain focused on the permission-query behavior described in issue #14679.
Title check ✅ Passed The title clearly and concisely describes the main change: returning a real PermissionStatus from the browser query override.
Description check ✅ Passed The description covers the change, rationale, linked issue, testing, visual proof, and key compatibility considerations; some optional template sections are omitted.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Rebased onto main after #14685 landed in the same file. Both changes coexist:
#14685's Firefox gating and narrowed promptPerms are preserved untouched, and
this change replaces only the query-override implementation.

The previous Proxy bound every callable property, which broke three observable
things:
- onchange assignment threw "Illegal invocation" — the native setter received
  the proxy rather than the branded target.
- Listeners were delivered with the real target and the NATIVE state, so on a
  real permission change event.target.state read 'granted' while the returned
  status still read 'prompt'.
- Method reads returned a new bound function each time, so name became
  'bound addEventListener', toString lost its name, and identity was unstable.

Separately, the notifications state was captured once as a string, so an
already-returned status went stale after requestPermission updated it.

Shadow only 'state' on the genuine PermissionStatus with a lazy provider. The
object the site holds IS the real one, so identity, brand checks, method
fingerprints and native event delivery survive with nothing to keep in sync.

Verified against real Chromium (Chrome 151) rather than only the vm stand-in,
because the stand-in cannot show whether defineProperty succeeds on a branded
instance: the instance is extensible, the prototype 'state' accessor is
configurable, defineProperty succeeds, instanceof survives, addEventListener
keeps its native name and referential stability, and onchange assignment works.

New tests live in their own file rather than merged into anti-detection.test.ts,
whose harness diverged on main. The fallback test targets 'camera' because
#14685 narrowed the intercepted set, so a name outside it never reaches the
fallback.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/fix-permissions-query-status branch from 7fc7b35 to 7aecff9 Compare August 15, 2026 06:11
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual proof — live guest webview, real before/after

Isolated dev instance from this worktree (ORCA_DEV_USER_DATA_PATH=/tmp/orca-proof-84, renderer 5198, CDP 9382), identity re-asserted as fix-permissions-query-status before every step and port ownership checked with lsof+ps.

This is not a unit-test rerun. The probe runs inside a real Orca browser pane, in the guest <webview> where ANTI_DETECTION_SCRIPT is actually injected via Page.addScriptToEvaluateOnNewDocument (browser-manager.ts:293), reached over raw CDP since Playwright's connectOverCDP does not surface Electron webview targets as pages.

Before — src/main/browser/anti-detection.ts reverted to origin/main

"camera": {
  "state": "prompt",
  "isRealInstance": false,
  "ctorName": "Object",
  "hasAddEventListener": false,
  "addEventListenerIsNative": false,
  "sameMethodAsPrototype": false,
  "toStringTag": "[object Object]",
  "listenerAccepted": "THREW: cam.addEventListener is not a function"
}

The old code hands the page a plain object literal. Two consequences, both visible above:

  1. It is trivially detectable. [object Object] and constructor.name === "Object" where every real browser returns [object PermissionStatus]. A bot detector probing the shape of the object it just received sees an obvious forgery — which defeats the purpose of the anti-detection layer it lives in.
  2. It breaks real sites. addEventListener does not exist, so any site that registers a permission-change listener — the documented, ordinary use of the Permissions API — throws.

After — this branch at f7793e272d

"camera": {
  "state": "prompt",
  "isRealInstance": true,
  "ctorName": "PermissionStatus",
  "hasAddEventListener": true,
  "addEventListenerIsNative": true,
  "sameMethodAsPrototype": true,
  "hasOwnStateProp": true,
  "toStringTag": "[object PermissionStatus]",
  "listenerAccepted": true
}

The page now receives the genuine native PermissionStatus. sameMethodAsPrototype: true and addEventListenerIsNative: true together show method identity is intact — the object was not wrapped, proxied, or rebuilt. hasOwnStateProp: true is the own-accessor doing the shadowing, and state still reads prompt.

Non-intercepted permissions are untouched, in both runs

"geolocation": { "state": "denied", "isRealInstance": true }

geolocation is outside promptPerms after #14685 narrowed it to camera/microphone, so it falls through to origQuery and reports the genuine native state. Confirms this PR does not widen the intercepted set.

Other signals unchanged across both runs: webdriver: false, plugins: 5, chrome.csi/chrome.loadTimes present as functions, chrome.runtime absent.

How the before/after was produced

git checkout origin/main -- src/main/browser/anti-detection.ts, then a full dev-server restart, then the probe; then git checkout HEAD -- to restore and verify.

One correction worth recording: my first attempt at the "before" probe was invalid. electron-vite dev did not rebuild the main bundle on that file change, so the app was still running the new code and the "before" output was identical to the "after". I caught it by grepping the built bundle (grep -c withOverriddenState out/main/index.js returned 2 while the source returned 0) and redid it with a real restart, confirming 0 occurrences in the bundle before taking the measurement above. The numbers in this comment come from the corrected run.

One further caveat on method: the first document loaded in a fresh guest can predate the injection, so both probes were taken after a subsequent navigation, with chrome.csi present as a function used as the check that the script was actually live in the document being measured.

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025
brennanb2025 merged commit e16a22e into main Aug 17, 2026
45 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…tablyai#14684)

* fix(browser): shadow PermissionStatus state instead of proxying it

Rebased onto main after stablyai#14685 landed in the same file. Both changes coexist:
stablyai#14685's Firefox gating and narrowed promptPerms are preserved untouched, and
this change replaces only the query-override implementation.

The previous Proxy bound every callable property, which broke three observable
things:
- onchange assignment threw "Illegal invocation" — the native setter received
  the proxy rather than the branded target.
- Listeners were delivered with the real target and the NATIVE state, so on a
  real permission change event.target.state read 'granted' while the returned
  status still read 'prompt'.
- Method reads returned a new bound function each time, so name became
  'bound addEventListener', toString lost its name, and identity was unstable.

Separately, the notifications state was captured once as a string, so an
already-returned status went stale after requestPermission updated it.

Shadow only 'state' on the genuine PermissionStatus with a lazy provider. The
object the site holds IS the real one, so identity, brand checks, method
fingerprints and native event delivery survive with nothing to keep in sync.

Verified against real Chromium (Chrome 151) rather than only the vm stand-in,
because the stand-in cannot show whether defineProperty succeeds on a branded
instance: the instance is extensible, the prototype 'state' accessor is
configurable, defineProperty succeeds, instanceof survives, addEventListener
keeps its native name and referential stability, and onchange assignment works.

New tests live in their own file rather than merged into anti-detection.test.ts,
whose harness diverged on main. The fallback test targets 'camera' because
stablyai#14685 narrowed the intercepted set, so a name outside it never reaches the
fallback.

* test(browser): cover intercepted PermissionStatus identity
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#14684)

* fix(browser): shadow PermissionStatus state instead of proxying it

Rebased onto main after stablyai#14685 landed in the same file. Both changes coexist:
stablyai#14685's Firefox gating and narrowed promptPerms are preserved untouched, and
this change replaces only the query-override implementation.

The previous Proxy bound every callable property, which broke three observable
things:
- onchange assignment threw "Illegal invocation" — the native setter received
  the proxy rather than the branded target.
- Listeners were delivered with the real target and the NATIVE state, so on a
  real permission change event.target.state read 'granted' while the returned
  status still read 'prompt'.
- Method reads returned a new bound function each time, so name became
  'bound addEventListener', toString lost its name, and identity was unstable.

Separately, the notifications state was captured once as a string, so an
already-returned status went stale after requestPermission updated it.

Shadow only 'state' on the genuine PermissionStatus with a lazy provider. The
object the site holds IS the real one, so identity, brand checks, method
fingerprints and native event delivery survive with nothing to keep in sync.

Verified against real Chromium (Chrome 151) rather than only the vm stand-in,
because the stand-in cannot show whether defineProperty succeeds on a branded
instance: the instance is extensible, the prototype 'state' accessor is
configurable, defineProperty succeeds, instanceof survives, addEventListener
keeps its native name and referential stability, and onchange assignment works.

New tests live in their own file rather than merged into anti-detection.test.ts,
whose harness diverged on main. The fallback test targets 'camera' because
stablyai#14685 narrowed the intercepted set, so a name outside it never reaches the
fallback.

* test(browser): cover intercepted PermissionStatus identity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: navigator.permissions.query returns a non-spec object, so addEventListener throws

1 participant