-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
643a166
to
cfaaeb0
Compare
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) |
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.
Should be (permissions[, options])
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
@@ -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']); |
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.
await context.grantPermissions(...)
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
@@ -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(); |
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.
await here as well.
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 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", |
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.
Stray change?
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.
Very
} | ||
|
||
async clearPermissions() { | ||
this._permissions.clear(); |
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.
It is confusing that we don't call _doClearPermissions
here.
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 thought the same way. Fixing.
src/chromium/crBrowser.ts
Outdated
} | ||
|
||
async clearPermissions() { | ||
super.clearPermissions(); |
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.
Please await this, since it's an async function.
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
src/webkit/wkBrowser.ts
Outdated
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); |
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.
await it
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
test/permissions.spec.js
Outdated
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 }); |
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.
This is some funky syntax 😄
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.
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 }); |
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.
server.EMPTY_PAGE
is not quite an origin. Do we support urls? I don't see where we convert url to an 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.
I think it happens inside the browsers :/
2c22a09
to
0e77909
Compare
0e77909
to
6520cfc
Compare
No description provided.