Skip to content
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

Merged
merged 4 commits into from Aug 30, 2018

Conversation

aslushnikov
Copy link
Contributor

Introduce an API to manage permissions per browser context:

  • BrowserContext.overridePermissions(origin, permissions)
  • BrowserContext.resetPermissionOverrides()

Fixes #846.

Introduce an API to manage permissions per browser context:
- BrowserContext.overridePermissions(origin, permissions)
- BrowserContext.resetPermissionOverrides()

Fixes puppeteer#846.
Copy link
Collaborator

@JoelEinbinder JoelEinbinder left a 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()
Copy link
Collaborator

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?

Copy link
Contributor Author

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()
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

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.

Copy link
Contributor Author

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
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The origin...

Copy link
Contributor Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it though?

Copy link
Contributor Author

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

Copy link
Contributor Author

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:
Copy link
Collaborator

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:

Copy link
Contributor Author

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) {
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@aslushnikov
Copy link
Contributor Author

Are any permissions on by default?

They might be if launched with pre-initialized userDataDir.

@aslushnikov aslushnikov merged commit 50d6c2d into puppeteer:master Aug 30, 2018
@aslushnikov aslushnikov deleted the permissions branch November 2, 2018 19:44
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.

None yet

2 participants