grantPermissions(permissions[, options])
授予指定的权限给 browser context。
参数 | 类型 | 描述 |
---|---|---|
permissions | array | 一个字符串数组,包含要授予的权限。权限可以是以下值之一:'geolocation' , 'midi' , 'midi-sysex' (system-exclusive midi), 'notifications' , 'camera' , 'microphone' , 'background-sync' , 'ambient-light-sensor' , 'accelerometer' , 'gyroscope' , 'magnetometer' , 'accessibility-events' , 'clipboard-read' , 'clipboard-write' , 'payment-handler' 。 |
options | object | 可选。 |
options.origin | string | 要授予权限的来源,例如 'https://example.com' 。 |
返回值
类型 | 描述 |
---|---|
Promise<void> | 当权限被授予时,此 Promise 将 fulfilled。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const context = await browser.newContext();
await context.grantPermissions(['clipboard-read', 'clipboard-write'], {
origin: 'https://example.com/',
});
}