{"record":{"id":"1fe42149a4280db4","repo":"garrytan/gstack","slug":"usage-screenshot-selector-css-path","errorCode":null,"errorMessage":"Usage: screenshot --selector <css> [path]","messagePattern":"Usage: screenshot --selector <css> \\[path\\]","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/meta-commands.ts","lineNumber":454,"sourceCode":"    case 'screenshot': {\n      // Parse priority: flags (--viewport, --clip, --base64) → selector (@ref, CSS) → output path\n      const page = bm.getPage();\n      let outputPath = `${TEMP_DIR}/browse-screenshot.png`;\n      let clipRect: { x: number; y: number; width: number; height: number } | undefined;\n      let targetSelector: string | undefined;\n      let viewportOnly = false;\n      let base64Mode = false;\n\n      const remaining: string[] = [];\n      let flagSelector: string | undefined;\n      for (let i = 0; i < args.length; i++) {\n        if (args[i] === '--viewport') {\n          viewportOnly = true;\n        } else if (args[i] === '--base64') {\n          base64Mode = true;\n        } else if (args[i] === '--selector') {\n          flagSelector = args[++i];\n          if (!flagSelector) throw new Error('Usage: screenshot --selector <css> [path]');\n        } else if (args[i] === '--clip') {\n          const coords = args[++i];\n          if (!coords) throw new Error('Usage: screenshot --clip x,y,w,h [path]');\n          const parts = coords.split(',').map(Number);\n          if (parts.length !== 4 || parts.some(isNaN))\n            throw new Error('Usage: screenshot --clip x,y,width,height — all must be numbers');\n          clipRect = { x: parts[0], y: parts[1], width: parts[2], height: parts[3] };\n        } else if (args[i].startsWith('--')) {\n          throw new Error(`Unknown screenshot flag: ${args[i]}`);\n        } else {\n          remaining.push(args[i]);\n        }\n      }\n\n      // Separate target (selector/@ref) from output path\n      for (const arg of remaining) {\n        // File paths containing / and ending with an image/pdf extension are never CSS selectors\n        const isFilePath = arg.includes('/') && /\\.(png|jpe?g|webp|pdf)$/i.test(arg);","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/meta-commands.ts#L436-L472","documentation":"Thrown by the screenshot command when --selector is the last token in argv — the (++i) increment reads undefined. The --selector flag requires a following CSS selector string to specify which DOM element to capture.","triggerScenarios":"Passing '--selector' as the final argument with no subsequent value, e.g., 'screenshot --selector'.","commonSituations":"User forgets to include the CSS selector, or a script omits the selector value when constructing the command.","solutions":["Provide the CSS selector immediately after --selector, e.g., 'screenshot --selector #main-content out.png'","If building the command programmatically, ensure the selector variable is non-empty"],"exampleFix":"# before\n$B screenshot --selector\n\n# after\n$B screenshot --selector '#main-content' out.png","handlingStrategy":"validation","validationCode":"const idx = args.indexOf('--selector');\nif (idx !== -1 && (idx === args.length - 1 || !args[idx + 1])) {\n  throw new Error('--selector requires a CSS value');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide the CSS selector string immediately after --selector","Validate programmatically constructed commands to ensure no flag is left valueless"],"tags":["screenshot","cli","argument-parsing"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}