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(permissions): make origin optional #1406

Merged
merged 1 commit into from
Mar 17, 2020

Conversation

pavelfeldman
Copy link
Member

No description provided.

@pavelfeldman pavelfeldman force-pushed the fe_permissions branch 2 times, most recently from 643a166 to cfaaeb0 Compare March 17, 2020 00:41
docs/api.md Outdated
#### browserContext.setPermissions(origin, permissions[])
- `origin` <[string]> The [origin] to grant permissions to, e.g. "https://example.com".
- `permissions` <[Array]<[string]>> An array of permissions to grant. All permissions that are not listed here will be automatically denied. Permissions can be one of the following values:
#### browserContext.grantPermissions(permissions[], options)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be (permissions[, options])

Copy link
Member 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
@@ -381,7 +381,7 @@ Clears all permission overrides for the browser context.

```js
const context = await browser.newContext();
context.setPermissions('https://example.com', ['clipboard-read']);
context.grantPermissions(['clipboard-read']);
Copy link
Contributor

Choose a reason for hiding this comment

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

await context.grantPermissions(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -381,7 +381,7 @@ Clears all permission overrides for the browser context.

```js
const context = await browser.newContext();
context.setPermissions('https://example.com', ['clipboard-read']);
context.grantPermissions(['clipboard-read']);
// do stuff ..
context.clearPermissions();
Copy link
Contributor

Choose a reason for hiding this comment

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

await here as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done as well

package.json Outdated
@@ -46,6 +46,7 @@
"extract-zip": "^1.6.6",
"https-proxy-agent": "^3.0.0",
"jpeg-js": "^0.3.6",
"playwright": "^0.11.1-next.1583993157193",
Copy link
Contributor

Choose a reason for hiding this comment

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

Stray change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Very

}

async clearPermissions() {
this._permissions.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

It is confusing that we don't call _doClearPermissions here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought the same way. Fixing.

}

async clearPermissions() {
super.clearPermissions();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please await this, since it's an async function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

const entries = Object.entries(this._options.permissions || {});
await Promise.all(entries.map(entry => this.setPermissions(entry[0], entry[1])));
if (this._options.permissions)
this.grantPermissions(this._options.permissions);
Copy link
Contributor

Choose a reason for hiding this comment

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

await it

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

expect(await getPermission(page, 'geolocation')).toBe('denied');
});
it('should fail when bad permission is given', async({page, server, context}) => {
await page.goto(server.EMPTY_PAGE);
let error = {};
await context.setPermissions(server.EMPTY_PAGE, ['foo']).catch(e => error = e);
await context.grantPermissions(['foo']).catch(e => error = e, { origin: server.EMPTY_PAGE });
Copy link
Contributor

Choose a reason for hiding this comment

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

This is some funky syntax 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

ooo

@@ -71,9 +103,9 @@ module.exports.describe = function({testRunner, expect, WEBKIT}) {
});
});
expect(await page.evaluate(() => window['events'])).toEqual(['prompt']);
await context.setPermissions(server.EMPTY_PAGE, []);
await context.grantPermissions([], { origin: server.EMPTY_PAGE });
Copy link
Contributor

Choose a reason for hiding this comment

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

server.EMPTY_PAGE is not quite an origin. Do we support urls? I don't see where we convert url to an origin.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it happens inside the browsers :/

@pavelfeldman pavelfeldman force-pushed the fe_permissions branch 2 times, most recently from 2c22a09 to 0e77909 Compare March 17, 2020 22:16
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.

2 participants