mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: expose puppeteer.Permission type (#6856)
* fix: expose puppeteer.Permission type A regression in our own types when compared to @types/puppeteer - we needed to expose the permissons.
This commit is contained in:
parent
ad5935738d
commit
a5e174f696
@ -26,6 +26,52 @@ import { Viewport } from './PuppeteerViewport.js';
|
|||||||
|
|
||||||
type BrowserCloseCallback = () => Promise<void> | void;
|
type BrowserCloseCallback = () => Promise<void> | void;
|
||||||
|
|
||||||
|
const WEB_PERMISSION_TO_PROTOCOL_PERMISSION = new Map<
|
||||||
|
Permission,
|
||||||
|
Protocol.Browser.PermissionType
|
||||||
|
>([
|
||||||
|
['geolocation', 'geolocation'],
|
||||||
|
['midi', 'midi'],
|
||||||
|
['notifications', 'notifications'],
|
||||||
|
// TODO: push isn't a valid type?
|
||||||
|
// ['push', 'push'],
|
||||||
|
['camera', 'videoCapture'],
|
||||||
|
['microphone', 'audioCapture'],
|
||||||
|
['background-sync', 'backgroundSync'],
|
||||||
|
['ambient-light-sensor', 'sensors'],
|
||||||
|
['accelerometer', 'sensors'],
|
||||||
|
['gyroscope', 'sensors'],
|
||||||
|
['magnetometer', 'sensors'],
|
||||||
|
['accessibility-events', 'accessibilityEvents'],
|
||||||
|
['clipboard-read', 'clipboardReadWrite'],
|
||||||
|
['clipboard-write', 'clipboardReadWrite'],
|
||||||
|
['payment-handler', 'paymentHandler'],
|
||||||
|
['idle-detection', 'idleDetection'],
|
||||||
|
// chrome-specific permissions we have.
|
||||||
|
['midi-sysex', 'midiSysex'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export type Permission =
|
||||||
|
| 'geolocation'
|
||||||
|
| 'midi'
|
||||||
|
| 'notifications'
|
||||||
|
| 'camera'
|
||||||
|
| 'microphone'
|
||||||
|
| 'background-sync'
|
||||||
|
| 'ambient-light-sensor'
|
||||||
|
| 'accelerometer'
|
||||||
|
| 'gyroscope'
|
||||||
|
| 'magnetometer'
|
||||||
|
| 'accessibility-events'
|
||||||
|
| 'clipboard-read'
|
||||||
|
| 'clipboard-write'
|
||||||
|
| 'payment-handler'
|
||||||
|
| 'idle-detection'
|
||||||
|
| 'midi-sysex';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -650,34 +696,12 @@ export class BrowserContext extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
async overridePermissions(
|
async overridePermissions(
|
||||||
origin: string,
|
origin: string,
|
||||||
permissions: string[]
|
permissions: Permission[]
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const webPermissionToProtocol = new Map<
|
|
||||||
string,
|
|
||||||
Protocol.Browser.PermissionType
|
|
||||||
>([
|
|
||||||
['geolocation', 'geolocation'],
|
|
||||||
['midi', 'midi'],
|
|
||||||
['notifications', 'notifications'],
|
|
||||||
// TODO: push isn't a valid type?
|
|
||||||
// ['push', 'push'],
|
|
||||||
['camera', 'videoCapture'],
|
|
||||||
['microphone', 'audioCapture'],
|
|
||||||
['background-sync', 'backgroundSync'],
|
|
||||||
['ambient-light-sensor', 'sensors'],
|
|
||||||
['accelerometer', 'sensors'],
|
|
||||||
['gyroscope', 'sensors'],
|
|
||||||
['magnetometer', 'sensors'],
|
|
||||||
['accessibility-events', 'accessibilityEvents'],
|
|
||||||
['clipboard-read', 'clipboardReadWrite'],
|
|
||||||
['clipboard-write', 'clipboardReadWrite'],
|
|
||||||
['payment-handler', 'paymentHandler'],
|
|
||||||
['idle-detection', 'idleDetection'],
|
|
||||||
// chrome-specific permissions we have.
|
|
||||||
['midi-sysex', 'midiSysex'],
|
|
||||||
]);
|
|
||||||
const protocolPermissions = permissions.map((permission) => {
|
const protocolPermissions = permissions.map((permission) => {
|
||||||
const protocolPermission = webPermissionToProtocol.get(permission);
|
const protocolPermission = WEB_PERMISSION_TO_PROTOCOL_PERMISSION.get(
|
||||||
|
permission
|
||||||
|
);
|
||||||
if (!protocolPermission)
|
if (!protocolPermission)
|
||||||
throw new Error('Unknown permission: ' + permission);
|
throw new Error('Unknown permission: ' + permission);
|
||||||
return protocolPermission;
|
return protocolPermission;
|
||||||
|
@ -260,6 +260,7 @@ describe('Page', function () {
|
|||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
let error = null;
|
let error = null;
|
||||||
await context
|
await context
|
||||||
|
// @ts-expect-error purposeful bad input for test
|
||||||
.overridePermissions(server.EMPTY_PAGE, ['foo'])
|
.overridePermissions(server.EMPTY_PAGE, ['foo'])
|
||||||
.catch((error_) => (error = error_));
|
.catch((error_) => (error = error_));
|
||||||
expect(error.message).toBe('Unknown permission: foo');
|
expect(error.message).toBe('Unknown permission: foo');
|
||||||
|
@ -857,6 +857,13 @@ function compareDocumentations(actual, expected) {
|
|||||||
'"none"|"achromatopsia"|"blurredVision"|"deuteranopia"|"protanopia"|"tritanopia"',
|
'"none"|"achromatopsia"|"blurredVision"|"deuteranopia"|"protanopia"|"tritanopia"',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'Method BrowserContext.overridePermissions() permissions',
|
||||||
|
{
|
||||||
|
actualName: 'Array<string>',
|
||||||
|
expectedName: 'Array<Permission>',
|
||||||
|
},
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const expectedForSource = expectedNamingMismatches.get(source);
|
const expectedForSource = expectedNamingMismatches.get(source);
|
||||||
|
Loading…
Reference in New Issue
Block a user