{"record":{"id":"14820ea22f169f18","repo":"garrytan/gstack","slug":"usage-browse-cookie-name-value","errorCode":null,"errorMessage":"Usage: browse cookie <name>=<value>","messagePattern":"Usage: browse cookie <name>=<value>","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"browse/src/write-commands.ts","lineNumber":557,"sourceCode":"        // headed → headless transitions or contexts with viewport:null.\n        const current = bm.getCurrentViewport();\n        w = current.width;\n        h = current.height;\n      }\n\n      if (scaleArg !== undefined) {\n        const err = await bm.setDeviceScaleFactor(scaleArg, w, h);\n        if (err) return `Viewport partially set: ${err}`;\n        return `Viewport set to ${w}x${h} @ ${scaleArg}x (context recreated; refs and load-html content replayed)`;\n      }\n\n      await bm.setViewport(w, h);\n      return `Viewport set to ${w}x${h}`;\n    }\n\n    case 'cookie': {\n      const cookieStr = args[0];\n      if (!cookieStr || !cookieStr.includes('=')) throw new Error('Usage: browse cookie <name>=<value>');\n      const eq = cookieStr.indexOf('=');\n      const name = cookieStr.slice(0, eq);\n      const value = cookieStr.slice(eq + 1);\n      const url = new URL(page.url());\n      await page.context().addCookies([{\n        name,\n        value,\n        domain: url.hostname,\n        path: '/',\n      }]);\n      return `Cookie set: ${name}=****`;\n    }\n\n    case 'header': {\n      const headerStr = args[0];\n      if (!headerStr || !headerStr.includes(':')) throw new Error('Usage: browse header <name>:<value>');\n      const sep = headerStr.indexOf(':');\n      const name = headerStr.slice(0, sep).trim();","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/write-commands.ts#L539-L575","documentation":"Thrown by `browse cookie` when the first argument is missing or does not contain an `=` character. The command parses a single `name=value` token by splitting on the first `=`; without that separator it cannot derive a cookie name and refuses to write a cookie whose name would be the entire string with an empty value.","triggerScenarios":"Calling `browse cookie` with no args; `browse cookie sessionid` (value omitted); `browse cookie sessionid:abc123` (wrong separator, a `:` leftover from header-style usage); quoting that strips the `=` when the shell splits the token.","commonSituations":"User conflates the cookie command (`name=value`) with the header command (`name:value`); an agent forwards a value that already URL-encoded the `=`; copy-pasting a `Set-Cookie:` header line that contains attributes after the first `;` works but the user assumed it would not and pre-trimmed at the wrong character.","solutions":["Provide the token as `name=value`: `browse cookie sessionid=abc123`.","Quote the whole token if the value contains characters the shell would split on: `browse cookie \"token=a=b=c\"` (only the FIRST `=` is used as the separator, so embedded `=` in the value is preserved).","If you wanted to set a header instead, use `browse header name:value`.","For bulk import including domain/path/expiry, use `browse cookie-import <file>` instead of setting one cookie at a time."],"exampleFix":"// before\nawait runBrowseCommand(['cookie', 'sessionid:abc123']);\n\n// after\nawait runBrowseCommand(['cookie', 'sessionid=abc123']);","handlingStrategy":"validation","validationCode":"function parseCookieToken(token: string): { name: string; value: string } {\n  if (!token || !token.includes('=')) {\n    throw new Error('cookie token must be name=value');\n  }\n  const eq = token.indexOf('=');\n  return { name: token.slice(0, eq), value: token.slice(eq + 1) };\n}","typeGuard":"function isCookieToken(s: string): boolean {\n  return typeof s === 'string' && s.includes('=') && s.indexOf('=') > 0;\n}","tryCatchPattern":null,"preventionTips":["Use '=' as the separator for cookies and ':' for headers — they are distinct commands.","Quote the token if the value contains characters the shell would split on.","Only the first '=' is the separator, so values may contain '='."],"tags":["cli-usage","cookies","argument-validation","browse-command"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}