{"record":{"id":"3c22e4680aea0ffe","repo":"grafana/k6","slug":"parsing-grant-permission-options-w","errorCode":null,"errorMessage":"parsing grant permission options: %w","messagePattern":"parsing grant permission options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/browser_context_mapping.go","lineNumber":86,"sourceCode":"\t\t\"clearPermissions\": func() *sobek.Promise {\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, bc.ClearPermissions() //nolint:wrapcheck\n\t\t\t})\n\t\t},\n\t\t\"close\": func() *sobek.Promise {\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, bc.Close() //nolint:wrapcheck\n\t\t\t})\n\t\t},\n\t\t\"cookies\": func(urls ...string) *sobek.Promise {\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn bc.Cookies(urls...) //nolint:wrapcheck\n\t\t\t})\n\t\t},\n\t\t\"grantPermissions\": func(permissions []string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := exportTo[common.GrantPermissionsOptions](vu.Runtime(), opts)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing grant permission options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, bc.GrantPermissions(permissions, popts)\n\t\t\t}), nil\n\t\t},\n\t\t\"setDefaultNavigationTimeout\": bc.SetDefaultNavigationTimeout,\n\t\t\"setDefaultTimeout\":           bc.SetDefaultTimeout,\n\t\t\"setGeolocation\": func(geolocation sobek.Value) (*sobek.Promise, error) {\n\t\t\tgl, err := exportTo[common.Geolocation](vu.Runtime(), geolocation)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing geo location: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, bc.SetGeolocation(&gl)\n\t\t\t}), nil\n\t\t},\n\t\t\"setHTTPCredentials\": func(httpCredentials sobek.Value) (*sobek.Promise, error) {\n\t\t\tcreds, err := exportTo[common.Credentials](rt, httpCredentials)","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/browser_context_mapping.go#L68-L104","documentation":"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.","triggerScenarios":"grantPermissions(['geolocation'], 'https://k6.io') (string instead of {origin:...}); grantPermissions(['notifications'], { origin: 123 }); passing an array or a primitive as the options argument.","commonSituations":"Copy-pasting from Playwright examples where the argument shape differs slightly; assuming the origin is positional; script-generated option objects with wrong value types.","solutions":["Pass the options as an object: grantPermissions(['geolocation'], { origin: 'https://k6.io' })","Omit the second argument entirely when no origin restriction is needed"],"exampleFix":"// before: origin passed as a plain string\ncontext.grantPermissions(['geolocation'], 'https://k6.io');\n\n// after: options object with an `origin` string\ncontext.grantPermissions(['geolocation'], { origin: 'https://k6.io' });","handlingStrategy":"type-guard","validationCode":"const opts = { origin: 'https://k6.io' };\nif (typeof opts.origin !== 'string') throw new TypeError('origin must be a string');\nawait context.grantPermissions(['geolocation'], opts);","typeGuard":"function isGrantPermissionsOptions(v) {\n  return (\n    v == null ||\n    (typeof v === 'object' &&\n      !Array.isArray(v) &&\n      (v.origin === undefined || typeof v.origin === 'string'))\n  );\n}","tryCatchPattern":"try {\n  await context.grantPermissions(perms, opts);\n} catch (e) {\n  if (String(e).includes('parsing grant permission options')) {\n    // bad options shape - fall back to no origin restriction\n    await context.grantPermissions(perms);\n  } else throw e;\n}","preventionTips":["Memorize the shape: second argument is { origin?: string } or omitted","Keep a typed helper for browser-context option objects instead of ad-hoc literals"],"tags":["browser","browser-context","grant-permissions","options-parsing"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}