feat(cdp): honor Browser.grantPermissions / setPermission / resetPermissions#2727
Conversation
| const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded; | ||
| const page = bc.session.currentPage() orelse return error.PageNotLoaded; | ||
| for (params.permissions) |name| { | ||
| try page.setPermission(name, .granted); |
There was a problem hiding this comment.
Shouldn't we set permissions at the browser's level?
Here, any permission set via CDP will be lost with the page.
Also regarding the origin support, if we don't support it right now, we should at least write down a not_implemented log.
Same about browserContextId.
|
Thanks for the review. Addressed all three points:
The test now asserts the state on the browser. `make test` passes (796/796, no leaks), `zig fmt --check` is clean, and `make build` succeeds. |
5f23b86 to
da08031
Compare
|
Rebased the browser-level change on top of your |
…issions These three Browser methods were noops, so a CDP client could not change what navigator.permissions.query() reports - it always returned "prompt". Store permission state on the active Page (keyed by permission name) and have navigator.permissions.query() read it back. grantPermissions sets each listed permission to "granted", setPermission sets a single permission to an explicit state, and resetPermissions clears them (query falls back to "prompt"). State is scoped to the Page and resets on navigation. Adds a CDP round-trip test exercising all three methods.
Address review: permissions set via Browser.grantPermissions / setPermission now live on the Browser instead of the active Page, so they persist across page navigations (previously a navigation dropped them) and match how Chrome scopes permissions to the browser context. navigator.permissions.query() reads the browser-level state. Also log not_implemented for the origin and browserContextId params, which are accepted but not yet honored.
da08031 to
a0fc38e
Compare
Browser.grantPermissions,Browser.setPermissionandBrowser.resetPermissionswere noops, so a CDP automation client (Puppeteer'sbrowserContext.grantPermissions(['geolocation']), Playwright'scontext.grantPermissions) could not influence whatnavigator.permissions.query()returns. The query always reported"prompt"regardless. This is a gap for automation flows that need to pre-grant or deny permissions (geolocation, notifications, clipboard, etc.) before a page runs.Changes
src/browser/Page.zig: store permission state on the Page, keyed by permission name, with a smallsetPermissionhelper. Keys and values are duped into the Page arena, so the state lives for (and resets with) the Page.src/cdp/domains/browser.zig: implement the three methods.grantPermissionssets each listed permission to"granted";setPermissionsets a single permission to an explicit"granted"/"denied"/"prompt"state;resetPermissionsclears the map.src/browser/webapi/Permissions.zig:navigator.permissions.query()now reads the stored state and falls back to"prompt"when unset (previously hardcoded"prompt").Scope note
Permission state is stored on the active
Page, so it resets on navigation. CDP scopes these methods to a browser context (state persists across navigations); persisting across navigations would mean storing on the CDPBrowserContextand re-applying on each new Page, which I left as a follow-up to keep this change small. Theorigin/browserContextIdparameters are accepted and ignored for now.Verified
make testpasses (796/796, no leaks); new testcdp.browser: grant/set/reset permissions reach navigator.permissionsdrives all three methods throughprocessMessageand asserts the stored state.zig fmt --check ./*.zig ./**/*.zigclean.make buildsucceeds.