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
3 changes: 2 additions & 1 deletion docs/src/api/class-browsercontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,14 +948,15 @@ Here are some permissions that may be supported by some browsers:
* `'clipboard-write'`
* `'geolocation'`
* `'gyroscope'`
* `'local-fonts'`
* `'local-network-access'`
* `'magnetometer'`
* `'microphone'`
* `'midi-sysex'` (system-exclusive midi)
* `'midi'`
* `'notifications'`
* `'payment-handler'`
* `'storage-access'`
* `'local-fonts'`

### option: BrowserContext.grantPermissions.origin
* since: v1.8
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8991,14 +8991,15 @@ export interface BrowserContext {
* - `'clipboard-write'`
* - `'geolocation'`
* - `'gyroscope'`
* - `'local-fonts'`
* - `'local-network-access'`
* - `'magnetometer'`
* - `'microphone'`
* - `'midi-sysex'` (system-exclusive midi)
* - `'midi'`
* - `'notifications'`
* - `'payment-handler'`
* - `'storage-access'`
* - `'local-fonts'`
* @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 @@ -435,6 +435,7 @@ export class CRBrowserContext extends BrowserContext {
['midi-sysex', 'midiSysex'],
['storage-access', 'storageAccess'],
['local-fonts', 'localFonts'],
['local-network-access', 'localNetworkAccess'],
]);
const filtered = permissions.map(permission => {
const protocolPermission = webPermissionToProtocol.get(permission);
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8991,14 +8991,15 @@ export interface BrowserContext {
* - `'clipboard-write'`
* - `'geolocation'`
* - `'gyroscope'`
* - `'local-fonts'`
* - `'local-network-access'`
* - `'magnetometer'`
* - `'microphone'`
* - `'midi-sysex'` (system-exclusive midi)
* - `'midi'`
* - `'notifications'`
* - `'payment-handler'`
* - `'storage-access'`
* - `'local-fonts'`
* @param options
*/
grantPermissions(permissions: ReadonlyArray<string>, options?: {
Expand Down
48 changes: 48 additions & 0 deletions tests/library/permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,51 @@ it.describe(() => {
expect(await page.evaluate(async () => (await (window as any).queryLocalFonts()).length > 0)).toBe(true);
});
});

it('local network request is allowed from public origin', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37861' }
}, async ({ page, context, server, browserName }) => {
it.fail(browserName === 'webkit');
if (browserName === 'chromium')
await context.grantPermissions(['local-network-access']);
const serverRequests = [];
server.setRoute('/cors', (req, res) => {
serverRequests.push(`${req.method} ${req.url}`);
if (req.method === 'OPTIONS') {
res.writeHead(204, {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
'Access-Control-Allow-Headers': '*',
});
res.end();
return;
}
res.writeHead(200, { 'Content-type': 'text/plain', 'Access-Control-Allow-Origin': '*' });
res.end('Hello there!');
});
const clientRequests = [];
// Has to be a public origin.
await page.goto('https://demo.playwright.dev/todomvc/');
page.on('request', request => {
clientRequests.push(`${request.method()} ${request.url()}`);
});
const response = await page.evaluate(async url => {
const response = await fetch(url, {
method: 'POST',
body: '',
headers: {
'Content-Type': 'application/json',
'X-Custom-Header': 'test-value'
}
});
return await response.text();
}, server.CROSS_PROCESS_PREFIX + '/cors').catch(e => e.message);
expect(response).toBe('Hello there!');
expect(serverRequests).toEqual([
'OPTIONS /cors',
'POST /cors',
]);
expect(clientRequests).toEqual([
`POST ${server.CROSS_PROCESS_PREFIX}/cors`,
]);
});
Loading