{"record":{"id":"7d253a905b44d2f1","repo":"garrytan/gstack","slug":"usage-browse-goto-url","errorCode":null,"errorMessage":"Usage: browse goto <url>","messagePattern":"Usage: browse goto <url>","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"browse/src/write-commands.ts","lineNumber":147,"sourceCode":"  ],\n};\n\nexport async function handleWriteCommand(\n  command: string,\n  args: string[],\n  session: TabSession,\n  bm: BrowserManager\n): Promise<string> {\n  const page = session.getPage();\n  // Frame-aware target for locator-based operations (click, fill, etc.)\n  const target = session.getActiveFrameOrPage();\n  const inFrame = session.getFrame() !== null;\n\n  switch (command) {\n    case 'goto': {\n      if (inFrame) throw new Error('Cannot use goto inside a frame. Run \\'frame main\\' first.');\n      const url = args[0];\n      if (!url) throw new Error('Usage: browse goto <url>');\n      // Clear loadedHtml BEFORE navigation — a timeout after the main-frame commit\n      // must not leave stale content that could resurrect on a later context recreation.\n      session.clearLoadedHtml();\n      const normalizedUrl = await validateNavigationUrl(url);\n      const response = await page.goto(normalizedUrl, { waitUntil: 'domcontentloaded', timeout: 15000 });\n      const status = response?.status() || 'unknown';\n      return `Navigated to ${normalizedUrl} (${status})`;\n    }\n\n    case 'back': {\n      if (inFrame) throw new Error('Cannot use back inside a frame. Run \\'frame main\\' first.');\n      session.clearLoadedHtml();\n      await page.goBack({ waitUntil: 'domcontentloaded', timeout: 15000 });\n      return `Back → ${page.url()}`;\n    }\n\n    case 'forward': {\n      if (inFrame) throw new Error('Cannot use forward inside a frame. Run \\'frame main\\' first.');","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/write-commands.ts#L129-L165","documentation":"Usage guard at write-commands.ts:147. The goto command requires a URL argument; args[0] is undefined or empty. This is a pure argument-count check before any URL parsing.","triggerScenarios":"Calling 'goto' with no arguments, or with an empty-string argument (browse goto '').","commonSituations":"Scripted call where the URL variable was undefined/null coerced to empty; a CLI typo dropping the URL token.","solutions":["Provide the URL as the first argument: goto <url>","In automation, assert the URL is a non-empty string before invoking goto"],"exampleFix":"// before\nawait handleWriteCommand('goto', [], session, bm)\n// after\nif (!url) throw new Error('url required')\nawait handleWriteCommand('goto', [url], session, bm)","handlingStrategy":"validation","validationCode":"function requireUrl(args: string[]): string {\n  const url = args[0]\n  if (!url || typeof url !== 'string') throw new Error('url required')\n  return url\n}","typeGuard":"function hasUrlArg(args: string[]): args is [string, ...string[]] {\n  return typeof args[0] === 'string' && args[0].length > 0\n}","tryCatchPattern":null,"preventionTips":["Validate the URL variable is a non-empty string before invoking goto","Default missing URLs to an explicit error in your own wrapper"],"tags":["usage","arguments","navigation","write-commands"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}