{"record":{"id":"1c8dd054c9f1896f","repo":"garrytan/gstack","slug":"cannot-use-reload-inside-a-frame-run-frame-main","errorCode":null,"errorMessage":"Cannot use reload inside a frame. Run 'frame main' first.","messagePattern":"Cannot use reload inside a frame\\. Run 'frame main' first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"browse/src/write-commands.ts","lineNumber":172,"sourceCode":"      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.');\n      session.clearLoadedHtml();\n      await page.goForward({ waitUntil: 'domcontentloaded', timeout: 15000 });\n      return `Forward → ${page.url()}`;\n    }\n\n    case 'reload': {\n      if (inFrame) throw new Error('Cannot use reload inside a frame. Run \\'frame main\\' first.');\n      session.clearLoadedHtml();\n      await page.reload({ waitUntil: 'domcontentloaded', timeout: 15000 });\n      return `Reloaded ${page.url()}`;\n    }\n\n    case 'load-html': {\n      if (inFrame) throw new Error('Cannot use load-html inside a frame. Run \\'frame main\\' first.');\n\n      // --from-file <path.json>: read inline HTML from a JSON payload. Used by\n      // make-pdf to dodge Windows argv size limits on large rendered HTML.\n      // The JSON shape is { html: string, waitUntil?: \"load\"|\"domcontentloaded\"|\"networkidle\" }.\n      // The safe-dirs + magic-byte + size-cap checks below still apply to the\n      // INLINE HTML content, not to the payload file path itself.\n      let fromFilePayload: { html: string; waitUntil?: SetContentWaitUntil } | null = null;\n      let filePath: string | undefined;\n      let waitUntil: SetContentWaitUntil = 'domcontentloaded';\n      for (let i = 0; i < args.length; i++) {\n        if (args[i] === '--from-file') {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/write-commands.ts#L154-L190","documentation":"Frame-context guard in the reload case at write-commands.ts:173. page.reload() targets the top-level page and is refused when a subframe context is active (session.getFrame() !== null).","triggerScenarios":"Running 'reload' while a frame context is active.","commonSituations":"Refreshing the page after interacting inside an iframe, forgetting the frame context is still set.","solutions":["Run 'frame main' before 'reload'","Issue reload before entering any frame in the flow","Guard on session.getFrame() === null"],"exampleFix":"// before\nawait handleWriteCommand('reload', [], session, bm)  // in frame → throws\n// after\nawait handleWriteCommand('frame', ['main'], session, bm)\nawait handleWriteCommand('reload', [], session, bm)","handlingStrategy":"validation","validationCode":"function canNavigate(session: { getFrame(): unknown }): boolean {\n  return session.getFrame() === null\n}","typeGuard":"function isMainFrameSession(s: { getFrame(): unknown }): boolean {\n  return s.getFrame() === null\n}","tryCatchPattern":null,"preventionTips":["Run 'frame main' before 'reload'","Reload before entering any frame","Assert getFrame() === null"],"tags":["frames","navigation","write-commands","session-state"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}