New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(browsercontext): implement BrowserContext.overridePermissions #3159
Conversation
Introduce an API to manage permissions per browser context: - BrowserContext.overridePermissions(origin, permissions) - BrowserContext.resetPermissionOverrides() Fixes puppeteer#846.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are any permissions on by default?
@@ -612,6 +615,11 @@ const page = await context.newPage(); | |||
await page.goto('https://example.com'); | |||
``` | |||
|
|||
#### browser.defaultBrowserContext() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this the mainBroswerContext to align with mainFrame?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no hierarchy between browser contexts.
docs/api.md
Outdated
#### browserContext.pages() | ||
- returns: <[Promise]<[Array]<[Page]>>> Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using [target.page()](#targetpage). | ||
|
||
An array of all pages inside the browser context. | ||
|
||
#### browserContext.resetPermissionOverrides() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClearPermissionOverrides? Reset feels like it might deny all permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/api.md
Outdated
#### browser.defaultBrowserContext() | ||
- returns: <[BrowserContext]> | ||
|
||
Returns default browser context. Default browser context cannot be closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns the default browser context. The default browser context can not be closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/api.md
Outdated
await context.overridePermissions('https://html5demos.com', ['geolocation']); | ||
``` | ||
|
||
> **NOTE** Permission management is scoped to browser context and is done per origins rather then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to fix the wording of this. But instead just remove this note. The api makes it clear how it works, and nobody needs to know why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/api.md
Outdated
@@ -719,11 +727,56 @@ The default browser context is the only non-incognito browser context. | |||
|
|||
Creates a new page in the browser context. | |||
|
|||
|
|||
#### browserContext.overridePermissions(origin, permissions) | |||
- `origin` <[string]> An [origin] to grant permissions to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. “https://example.com”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The origin...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
docs/api.md
Outdated
- `'clipboard-read'` | ||
- `'clipboard-write'` | ||
- `'payment-handler'` | ||
- `'flash'` (chrome-specific permission) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's a permission to run flash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed flash for now.
docs/api.md
Outdated
|
||
#### browserContext.overridePermissions(origin, permissions) | ||
- `origin` <[string]> An [origin] to grant permissions to. | ||
- `permissions` <[Array]<[string]>> An array of permissions to grant. All permissions that are not listed here will be automatically denied. Permission might be one of the following values: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Permissions can be one of the following values:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/Browser.js
Outdated
* @param {string} origin | ||
* @param {!Array<string>} permissions | ||
*/ | ||
async _overridePermissions(contextId, origin, permissions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this code should be in the browser context. That way if we ever add a helper method for the default browser context on the browser, it won’t conflict with the internal method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
They might be if launched with pre-initialized userDataDir. |
Introduce an API to manage permissions per browser context:
Fixes #846.