Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/api/class-browsercontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ Here are some permissions that may be supported by some browsers:
* `'notifications'`
* `'payment-handler'`
* `'storage-access'`
* `'screen-wake-lock'`

### option: BrowserContext.grantPermissions.origin
* since: v1.8
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9339,6 +9339,7 @@ export interface BrowserContext {
* - `'notifications'`
* - `'payment-handler'`
* - `'storage-access'`
* - `'screen-wake-lock'`
* @param options
*/
grantPermissions(permissions: ReadonlyArray<string>, options?: {
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/server/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export class CRBrowserContext extends BrowserContext<CREventsMap> {
['storage-access', 'storageAccess'],
['local-fonts', 'localFonts'],
['local-network-access', ['localNetworkAccess', 'localNetwork', 'loopbackNetwork']],
['screen-wake-lock', 'wakeLockScreen'],
]);

const grantPermissions = async (mapping: Map<string, Protocol.Browser.PermissionType | Protocol.Browser.PermissionType[]>) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/firefox/ffBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,12 @@ export class FFBrowserContext extends BrowserContext {
}

async doGrantPermissions(origin: string, permissions: string[]) {
const webPermissionToProtocol = new Map<string, 'geo' | 'desktop-notification' | 'persistent-storage' | 'push'>([
const webPermissionToProtocol = new Map<string, string>([
['geolocation', 'geo'],
['persistent-storage', 'persistent-storage'],
['push', 'push'],
['notifications', 'desktop-notification'],
['screen-wake-lock', 'screen-wake-lock'],
]);
const filtered = permissions.map(permission => {
const protocolPermission = webPermissionToProtocol.get(permission);
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/server/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ export class WKPage implements PageDelegate {
['geolocation', 'geolocation'],
['notifications', 'notifications'],
['clipboard-read', 'clipboard-read'],
['screen-wake-lock', 'screen-wake-lock'],
]);
const filtered = permissions.map(permission => {
const protocolPermission = webPermissionToProtocol.get(permission);
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9339,6 +9339,7 @@ export interface BrowserContext {
* - `'notifications'`
* - `'payment-handler'`
* - `'storage-access'`
* - `'screen-wake-lock'`
* @param options
*/
grantPermissions(permissions: ReadonlyArray<string>, options?: {
Expand Down
9 changes: 9 additions & 0 deletions tests/library/permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,12 @@ it('local network request is allowed from public origin', {
`POST ${server.CROSS_PROCESS_PREFIX}/cors`,
]);
});

it('can request screen-wake-lock', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/39115' }
}, async ({ page, context }) => {
await context.grantPermissions(['screen-wake-lock']);
await page.route('**/*', route => route.fulfill({ status: 200, body: '<div>Hello there!</div>', contentType: 'text/html' }));
await page.goto('https://example.com');
await page.evaluate(() => navigator.wakeLock.request('screen'));
});
Loading