grafana/k6 · error
parsing grant permission options: %w
Error message
parsing grant permission options: %w
What it means
browserContext.grantPermissions(permissions, opts) converts the second argument via exportTo[common.GrantPermissionsOptions], which expects an object with a single optional `origin` string. If the Sobek value cannot be exported to that shape, the conversion error is wrapped in this message before any CDP call is made.
Source
Thrown at internal/js/modules/k6/browser/browser/browser_context_mapping.go:86
"clearPermissions": func() *sobek.Promise {
return promise(vu, func() (any, error) {
return nil, bc.ClearPermissions() //nolint:wrapcheck
})
},
"close": func() *sobek.Promise {
return promise(vu, func() (any, error) {
return nil, bc.Close() //nolint:wrapcheck
})
},
"cookies": func(urls ...string) *sobek.Promise {
return promise(vu, func() (any, error) {
return bc.Cookies(urls...) //nolint:wrapcheck
})
},
"grantPermissions": func(permissions []string, opts sobek.Value) (*sobek.Promise, error) {
popts, err := exportTo[common.GrantPermissionsOptions](vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing grant permission options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, bc.GrantPermissions(permissions, popts)
}), nil
},
"setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout,
"setDefaultTimeout": bc.SetDefaultTimeout,
"setGeolocation": func(geolocation sobek.Value) (*sobek.Promise, error) {
gl, err := exportTo[common.Geolocation](vu.Runtime(), geolocation)
if err != nil {
return nil, fmt.Errorf("parsing geo location: %w", err)
}
return promise(vu, func() (any, error) {
return nil, bc.SetGeolocation(&gl)
}), nil
},
"setHTTPCredentials": func(httpCredentials sobek.Value) (*sobek.Promise, error) {
creds, err := exportTo[common.Credentials](rt, httpCredentials)View on GitHub (pinned to 93accf6570)
Solutions
- Pass the options as an object: grantPermissions(['geolocation'], { origin: 'https://k6.io' })
- Omit the second argument entirely when no origin restriction is needed
Example fix
// before: origin passed as a plain string
context.grantPermissions(['geolocation'], 'https://k6.io');
// after: options object with an `origin` string
context.grantPermissions(['geolocation'], { origin: 'https://k6.io' }); Defensive patterns
Strategy: type-guard
Validate before calling
const opts = { origin: 'https://k6.io' };
if (typeof opts.origin !== 'string') throw new TypeError('origin must be a string');
await context.grantPermissions(['geolocation'], opts); Type guard
function isGrantPermissionsOptions(v) {
return (
v == null ||
(typeof v === 'object' &&
!Array.isArray(v) &&
(v.origin === undefined || typeof v.origin === 'string'))
);
} Try / catch
try {
await context.grantPermissions(perms, opts);
} catch (e) {
if (String(e).includes('parsing grant permission options')) {
// bad options shape - fall back to no origin restriction
await context.grantPermissions(perms);
} else throw e;
} Prevention
- Memorize the shape: second argument is { origin?: string } or omitted
- Keep a typed helper for browser-context option objects instead of ad-hoc literals
When it happens
Trigger: grantPermissions(['geolocation'], 'https://k6.io') (string instead of {origin:...}); grantPermissions(['notifications'], { origin: 123 }); passing an array or a primitive as the options argument.
Common situations: Copy-pasting from Playwright examples where the argument shape differs slightly; assuming the origin is positional; script-generated option objects with wrong value types.
Related errors
- parsing geo location: %w
- parsing HTTP credentials: %w
- parsing wait for event options: %w
- parsing browser.newContext options: %w
- parsing browser.newPage options: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/3c22e4680aea0ffe.
Report an issue: GitHub.