feat(chromium): storage-access permission (#31239)

Fixes https://github.com/microsoft/playwright/issues/31227
This commit is contained in:
Yury Semikhatsky 2024-06-11 09:18:45 -07:00 committed by GitHub
parent f95b4e0ac8
commit c08000b967
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 20 deletions

View File

@ -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

View File

@ -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);

View File

@ -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?: {

View File

@ -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);
});