mirror of
https://github.com/microsoft/playwright.git
synced 2024-09-11 20:37:54 +03:00
feat(chromium): storage-access permission (#31239)
Fixes https://github.com/microsoft/playwright/issues/31227
This commit is contained in:
parent
f95b4e0ac8
commit
c08000b967
@ -1044,21 +1044,22 @@ specified.
|
||||
- `permissions` <[Array]<[string]>>
|
||||
|
||||
A permission or an array of permissions to grant. Permissions can be one of the following values:
|
||||
* `'geolocation'`
|
||||
* `'midi'`
|
||||
* `'midi-sysex'` (system-exclusive midi)
|
||||
* `'notifications'`
|
||||
* `'camera'`
|
||||
* `'microphone'`
|
||||
* `'background-sync'`
|
||||
* `'ambient-light-sensor'`
|
||||
* `'accelerometer'`
|
||||
* `'gyroscope'`
|
||||
* `'magnetometer'`
|
||||
* `'accessibility-events'`
|
||||
* `'ambient-light-sensor'`
|
||||
* `'background-sync'`
|
||||
* `'camera'`
|
||||
* `'clipboard-read'`
|
||||
* `'clipboard-write'`
|
||||
* `'geolocation'`
|
||||
* `'gyroscope'`
|
||||
* `'magnetometer'`
|
||||
* `'microphone'`
|
||||
* `'midi-sysex'` (system-exclusive midi)
|
||||
* `'midi'`
|
||||
* `'notifications'`
|
||||
* `'payment-handler'`
|
||||
* `'storage-access'`
|
||||
|
||||
### option: BrowserContext.grantPermissions.origin
|
||||
* since: v1.8
|
||||
|
@ -433,6 +433,7 @@ export class CRBrowserContext extends BrowserContext {
|
||||
['payment-handler', 'paymentHandler'],
|
||||
// chrome-specific permissions we have.
|
||||
['midi-sysex', 'midiSysex'],
|
||||
['storage-access', 'storageAccess'],
|
||||
]);
|
||||
const filtered = permissions.map(permission => {
|
||||
const protocolPermission = webPermissionToProtocol.get(permission);
|
||||
|
21
packages/playwright-core/types/types.d.ts
vendored
21
packages/playwright-core/types/types.d.ts
vendored
@ -8516,21 +8516,22 @@ export interface BrowserContext {
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
||||
* specified.
|
||||
* @param permissions A permission or an array of permissions to grant. Permissions can be one of the following values:
|
||||
* - `'geolocation'`
|
||||
* - `'midi'`
|
||||
* - `'midi-sysex'` (system-exclusive midi)
|
||||
* - `'notifications'`
|
||||
* - `'camera'`
|
||||
* - `'microphone'`
|
||||
* - `'background-sync'`
|
||||
* - `'ambient-light-sensor'`
|
||||
* - `'accelerometer'`
|
||||
* - `'gyroscope'`
|
||||
* - `'magnetometer'`
|
||||
* - `'accessibility-events'`
|
||||
* - `'ambient-light-sensor'`
|
||||
* - `'background-sync'`
|
||||
* - `'camera'`
|
||||
* - `'clipboard-read'`
|
||||
* - `'clipboard-write'`
|
||||
* - `'geolocation'`
|
||||
* - `'gyroscope'`
|
||||
* - `'magnetometer'`
|
||||
* - `'microphone'`
|
||||
* - `'midi-sysex'` (system-exclusive midi)
|
||||
* - `'midi'`
|
||||
* - `'notifications'`
|
||||
* - `'payment-handler'`
|
||||
* - `'storage-access'`
|
||||
* @param options
|
||||
*/
|
||||
grantPermissions(permissions: ReadonlyArray<string>, options?: {
|
||||
|
@ -172,3 +172,29 @@ it('should support clipboard read', async ({ page, context, server, browserName,
|
||||
await page.evaluate(() => navigator.clipboard.writeText('test content'));
|
||||
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe('test content');
|
||||
});
|
||||
|
||||
it('storage access', {
|
||||
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31227' }
|
||||
}, async ({ page, context, server, browserName }) => {
|
||||
it.fixme(browserName !== 'chromium');
|
||||
await context.grantPermissions(['storage-access']);
|
||||
expect(await getPermission(page, 'storage-access')).toBe('granted');
|
||||
server.setRoute('/set-cookie.html', (req, res) => {
|
||||
res.setHeader('Set-Cookie', 'name=value; Path=/; SameSite=Strict; Secure');
|
||||
res.end();
|
||||
});
|
||||
server.setRoute('/my-frame.html', (req, res) => {
|
||||
res.setHeader('Content-type', 'text/html');
|
||||
res.end(`<iframe src="${server.CROSS_PROCESS_PREFIX + '/empty.html'}"></iframe>`);
|
||||
});
|
||||
|
||||
// Navigate once to the domain as top level.
|
||||
await page.goto(server.CROSS_PROCESS_PREFIX + '/set-cookie.html');
|
||||
await page.goto(server.PREFIX + '/my-frame.html');
|
||||
|
||||
const frame = page.frames()[1];
|
||||
expect(await getPermission(frame, 'storage-access')).toBe('granted');
|
||||
const access = await frame.evaluate(() => document.requestStorageAccess().then(() => true, () => false));
|
||||
expect(access).toBe(true);
|
||||
expect(await frame.evaluate(() => document.hasStorageAccess())).toBe(true);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user