{"record":{"id":"c96afa0a9d942ac0","repo":"grafana/k6","slug":"invalid-browser-command-line-flag-s-v","errorCode":null,"errorMessage":"invalid browser command line flag: \"%s=%v\"","messagePattern":"invalid browser command line flag: \"(.+?)=(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/chromium/browser_type.go","lineNumber":416,"sourceCode":"\t}\n\n\treturn \"\", ErrChromeNotInstalled\n}\n\n// parseArgs parses command-line arguments and returns them.\nfunc parseArgs(flags map[string]any) ([]string, error) {\n\t// Build command line args list\n\tvar args []string\n\tfor name, value := range flags {\n\t\tswitch value := value.(type) {\n\t\tcase string:\n\t\t\targs = append(args, parseStringArg(name, value))\n\t\tcase bool:\n\t\t\tif value {\n\t\t\t\targs = append(args, fmt.Sprintf(\"--%s\", name))\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(`invalid browser command line flag: \"%s=%v\"`, name, value)\n\t\t}\n\t}\n\tif _, ok := flags[\"remote-debugging-port\"]; !ok {\n\t\targs = append(args, \"--remote-debugging-port=0\")\n\t}\n\n\t// Force the first page to be blank, instead of the welcome page;\n\t// --no-first-run doesn't enforce that.\n\t// args = append(args, common.BlankPage)\n\t// args = append(args, \"--no-startup-window\")\n\treturn args, nil\n}\n\nfunc parseStringArg(flag string, value string) string {\n\tif strings.TrimSpace(value) == \"\" {\n\t\t// If the value is empty, we don't include it in the args list.\n\t\t// Otherwise, it will produce \"--name=\" which is invalid.\n\t\treturn fmt.Sprintf(\"--%s\", flag)","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/chromium/browser_type.go#L398-L434","documentation":"Returned by parseArgs (reached via BrowserType.launch -> allocate) when the flags map built for the Chrome command line contains a value that is neither a string nor a bool. Every internal flag in prepareFlags is a string or bool, so in practice this fires when a custom entry — typically from options.args handling or a host-resolver-rules style string — ends up as another Go type (int, float, nil, map) and Chrome args cannot be rendered for it.","triggerScenarios":"chromium.launch() with an options value that flows a numeric flag into the flags map (e.g. a future/3rd-party option setting window-size as an int pair instead of the '800,600' string prepareFlags uses); programmatic use of the Go API putting an int/nil/struct value into the flags map consumed by allocate/parseArgs.","commonSituations":"Extensions or forks building flags maps programmatically and assuming any value type is accepted; k6 version drift where an option changed from string to typed value; scripts passing args like 'window-size=1024' that then get re-typed by custom glue code.","solutions":["Find the flag named in the error message (format is \"name=value\") and pass its value as a string, e.g. 'name=1024' in options.args","Keep custom launch args as 'flag=value' strings in the args option — k6 parses them into string flags itself","If you consume the Go API, ensure the map passed toward launch contains only bool or string values","Report a k6 bug if no custom args are set — with stock options all internal flags are string/bool"],"exampleFix":"// before (custom Go glue sets a typed value)\nflags[\"window-size\"] = 1024\n\n// after\nflags[\"window-size\"] = \"1024,768\"","handlingStrategy":"type-guard","validationCode":"// Keep launch args as plain 'name=value' strings\nconst args = ['window-size=1280,800', 'disable-gpu'];\nif (!args.every(a => typeof a === 'string' && /^[\\w-]+(=.+)?$/.test(a))) {\n  throw new Error('launch args must be strings of the form name[=value]');\n}","typeGuard":"function isStringOrBoolFlag(v) {\n  return typeof v === 'string' || typeof v === 'boolean';\n}\n// applies to Go consumers building the flags map:\n// if (!isStringOrBoolFlag(flags[name])) return error","tryCatchPattern":"try {\n  const browser = chromium.launch({ args });\n} catch (e) {\n  if (String(e.message).includes('invalid browser command line flag')) {\n    // the message names the offending \"name=value\" pair; fix its type\n    console.error('Flag values must be strings or booleans:', e.message);\n  }\n  throw e;\n}","preventionTips":["Pass custom flags exclusively through the args option as strings","Never inject typed values into flag maps when using the Go API","Validate arg strings with a name[=value] pattern check before launch"],"tags":["launch","command-line-flags","configuration","internal"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}