{"record":{"id":"cf9c2190d5342040","repo":"grafana/k6","slug":"parsing-geo-location-w","errorCode":null,"errorMessage":"parsing geo location: %w","messagePattern":"parsing geo location: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/browser_context_mapping.go","lineNumber":97,"sourceCode":"\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)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing HTTP credentials: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, bc.SetHTTPCredentials(creds) //nolint:staticcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"setOffline\": func(offline bool) *sobek.Promise {\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, bc.SetOffline(offline) //nolint:wrapcheck\n\t\t\t})","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/browser_context_mapping.go#L79-L115","documentation":"browserContext.setGeolocation(geolocation) exports its argument to common.Geolocation - a flat object with numeric latitude, longitude, and optional accuracy fields. A shape Sobek cannot export to that struct (a string, array, non-numeric coordinates, or wrong key names) fails conversion and surfaces wrapped in this error before any CDP traffic.","triggerScenarios":"setGeolocation('Paris'); setGeolocation(48.85); setGeolocation({ lat: 48.85, lng: 2.29 }) (wrong keys - the struct wants latitude/longitude); nested coordinate objects.","commonSituations":"Using abbreviated lat/lng key names from other geolocation APIs; passing a coordinates array from a mapping library; copy-pasting Playwright snippets with extra properties.","solutions":["Use the exact keys with numbers: setGeolocation({ latitude: 48.8584, longitude: 2.2945 })","Include accuracy only as a number if needed: { latitude, longitude, accuracy: 100 }","Omit the call entirely to keep the browser default geolocation"],"exampleFix":"// before: abbreviated keys -> export fails\nawait context.setGeolocation({ lat: 48.85, lng: 2.29 });\n\n// after: exact field names with numeric values\nawait context.setGeolocation({ latitude: 48.8584, longitude: 2.2945 });","handlingStrategy":"type-guard","validationCode":"const geo = { latitude: 48.8584, longitude: 2.2945 };\nconst ok = [geo.latitude, geo.longitude].every((n) => typeof n === 'number' && Number.isFinite(n));\nif (!ok) throw new TypeError('geolocation requires numeric latitude/longitude');\nawait context.setGeolocation(geo);","typeGuard":"function isGeolocation(v) {\n  return (\n    typeof v === 'object' &&\n    v !== null &&\n    !Array.isArray(v) &&\n    typeof v.latitude === 'number' &&\n    typeof v.longitude === 'number' &&\n    (v.accuracy === undefined || typeof v.accuracy === 'number')\n  );\n}","tryCatchPattern":"try {\n  await context.setGeolocation(geo);\n} catch (e) {\n  if (String(e).includes('parsing geo location')) {\n    console.warn('invalid geolocation shape - skipping');\n  } else throw e;\n}","preventionTips":["Use full key names latitude/longitude (not lat/lng) with plain numbers","Keep geolocation objects in one typed constant instead of inline literals at call sites"],"tags":["browser","browser-context","geolocation","options-parsing"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}