Repository navigation
fix(browser): return a real PermissionStatus from the query override - #14684
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe permission query override preserves native 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
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.
7fc7b35 to
7aecff9
Compare
Visual proof — live guest webview, real before/afterIsolated dev instance from this worktree ( This is not a unit-test rerun. The probe runs inside a real Orca browser pane, in the guest Before —
|
…issions-query-status
|
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. |
…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
…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
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 thePermissionStatusprototype was gone — noaddEventListener, noremoveEventListener, noinstanceof. Any site doingquery(...).then(s => s.addEventListener('change', ...))threw aTypeError.It now proxies the genuine status and overrides only
state, so the prototype, events andinstanceofsurvive. Where the real implementation rejects a name, it falls back to anEventTargetso listener registration still works instead of throwing.constructoris deliberately not bound — binding it madeconstructor.nameread"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:
permissions.query()returnsPermissionStatusObject.addEventListeneron itfunctionGmail 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
Extended the existing
runInNewContextharness inanti-detection.test.ts. The stand-inPermissionsnow resolves a realisticPermissionStatus(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:Gates: 40 files / 638 tests pass ·
pnpm typecheckclean ·oxlintclean ·oxfmt --checkclean.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
Proxyperpermissions.query()call, which sites call rarely.Checklist
max-linesdisable or baseline bump