Skip to content

Commit e6ef697

Browse files
committed
cherry-pick(#37871): chore: allow local-network-access permission in chromium
1 parent 932542c commit e6ef697

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

docs/src/api/class-browsercontext.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,15 @@ Here are some permissions that may be supported by some browsers:
948948
* `'clipboard-write'`
949949
* `'geolocation'`
950950
* `'gyroscope'`
951+
* `'local-fonts'`
952+
* `'local-network-access'`
951953
* `'magnetometer'`
952954
* `'microphone'`
953955
* `'midi-sysex'` (system-exclusive midi)
954956
* `'midi'`
955957
* `'notifications'`
956958
* `'payment-handler'`
957959
* `'storage-access'`
958-
* `'local-fonts'`
959960

960961
### option: BrowserContext.grantPermissions.origin
961962
* since: v1.8

packages/playwright-client/types/types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8991,14 +8991,15 @@ export interface BrowserContext {
89918991
* - `'clipboard-write'`
89928992
* - `'geolocation'`
89938993
* - `'gyroscope'`
8994+
* - `'local-fonts'`
8995+
* - `'local-network-access'`
89948996
* - `'magnetometer'`
89958997
* - `'microphone'`
89968998
* - `'midi-sysex'` (system-exclusive midi)
89978999
* - `'midi'`
89989000
* - `'notifications'`
89999001
* - `'payment-handler'`
90009002
* - `'storage-access'`
9001-
* - `'local-fonts'`
90029003
* @param options
90039004
*/
90049005
grantPermissions(permissions: ReadonlyArray<string>, options?: {

packages/playwright-core/src/server/chromium/crBrowser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ export class CRBrowserContext extends BrowserContext {
435435
['midi-sysex', 'midiSysex'],
436436
['storage-access', 'storageAccess'],
437437
['local-fonts', 'localFonts'],
438+
['local-network-access', 'localNetworkAccess'],
438439
]);
439440
const filtered = permissions.map(permission => {
440441
const protocolPermission = webPermissionToProtocol.get(permission);

packages/playwright-core/types/types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8991,14 +8991,15 @@ export interface BrowserContext {
89918991
* - `'clipboard-write'`
89928992
* - `'geolocation'`
89938993
* - `'gyroscope'`
8994+
* - `'local-fonts'`
8995+
* - `'local-network-access'`
89948996
* - `'magnetometer'`
89958997
* - `'microphone'`
89968998
* - `'midi-sysex'` (system-exclusive midi)
89978999
* - `'midi'`
89989000
* - `'notifications'`
89999001
* - `'payment-handler'`
90009002
* - `'storage-access'`
9001-
* - `'local-fonts'`
90029003
* @param options
90039004
*/
90049005
grantPermissions(permissions: ReadonlyArray<string>, options?: {

tests/library/permissions.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,51 @@ it.describe(() => {
253253
expect(await page.evaluate(async () => (await (window as any).queryLocalFonts()).length > 0)).toBe(true);
254254
});
255255
});
256+
257+
it('local network request is allowed from public origin', {
258+
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37861' }
259+
}, async ({ page, context, server, browserName }) => {
260+
it.fail(browserName === 'webkit');
261+
if (browserName === 'chromium')
262+
await context.grantPermissions(['local-network-access']);
263+
const serverRequests = [];
264+
server.setRoute('/cors', (req, res) => {
265+
serverRequests.push(`${req.method} ${req.url}`);
266+
if (req.method === 'OPTIONS') {
267+
res.writeHead(204, {
268+
'Access-Control-Allow-Origin': '*',
269+
'Access-Control-Allow-Methods': 'GET, POST, PUT, OPTIONS',
270+
'Access-Control-Allow-Headers': '*',
271+
});
272+
res.end();
273+
return;
274+
}
275+
res.writeHead(200, { 'Content-type': 'text/plain', 'Access-Control-Allow-Origin': '*' });
276+
res.end('Hello there!');
277+
});
278+
const clientRequests = [];
279+
// Has to be a public origin.
280+
await page.goto('https://demo.playwright.dev/todomvc/');
281+
page.on('request', request => {
282+
clientRequests.push(`${request.method()} ${request.url()}`);
283+
});
284+
const response = await page.evaluate(async url => {
285+
const response = await fetch(url, {
286+
method: 'POST',
287+
body: '',
288+
headers: {
289+
'Content-Type': 'application/json',
290+
'X-Custom-Header': 'test-value'
291+
}
292+
});
293+
return await response.text();
294+
}, server.CROSS_PROCESS_PREFIX + '/cors').catch(e => e.message);
295+
expect(response).toBe('Hello there!');
296+
expect(serverRequests).toEqual([
297+
'OPTIONS /cors',
298+
'POST /cors',
299+
]);
300+
expect(clientRequests).toEqual([
301+
`POST ${server.CROSS_PROCESS_PREFIX}/cors`,
302+
]);
303+
});

0 commit comments

Comments
 (0)