{"record":{"id":"1e72e4229363bf41","repo":"garrytan/gstack","slug":"load-html-absolutepath-has-ext-extension-bu","errorCode":null,"errorMessage":"load-html: ${absolutePath} has ${ext} extension but content does not look like HTML. First bytes: ${hexDump}","messagePattern":"load-html: (.+?) has (.+?) extension but content does not look like HTML\\. First bytes: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/write-commands.ts","lineNumber":315,"sourceCode":"\n      // Single read: Buffer → magic-byte peek → utf-8 string\n      const buf = await fs.promises.readFile(absolutePath);\n\n      // Magic-byte check: strip UTF-8 BOM + leading whitespace, then verify the first\n      // non-whitespace byte starts a markup construct. Accepts any <tag, <!doctype,\n      // <!-- comment, <?xml prolog — including bare HTML fragments like `<div>...</div>`\n      // which setContent wraps in a full document. Rejects binary files mis-renamed .html\n      // (first byte won't be `<`).\n      let peek = buf.slice(0, 200);\n      if (peek[0] === 0xEF && peek[1] === 0xBB && peek[2] === 0xBF) {\n        peek = peek.slice(3);\n      }\n      const peekStr = peek.toString('utf8').trimStart();\n      // Valid markup opener: '<' followed by alpha (tag), '!' (doctype/comment), or '?' (xml prolog)\n      const looksLikeMarkup = /^<[a-zA-Z!?]/.test(peekStr);\n      if (!looksLikeMarkup) {\n        const hexDump = Array.from(buf.slice(0, 16)).map(b => b.toString(16).padStart(2, '0')).join(' ');\n        throw new Error(\n          `load-html: ${absolutePath} has ${ext} extension but content does not look like HTML. First bytes: ${hexDump}`\n        );\n      }\n\n      const html = buf.toString('utf8');\n      await session.setTabContent(html, { waitUntil });\n      return `Loaded HTML: ${absolutePath} (${stat.size} bytes)`;\n    }\n\n    case 'click': {\n      const selector = args[0];\n      if (!selector) throw new Error('Usage: browse click <selector>');\n\n      // Auto-route: if ref points to a real <option> inside a <select>, use selectOption\n      const role = session.getRefRole(selector);\n      if (role === 'option') {\n        const resolved = await session.resolveRef(selector);\n        if ('locator' in resolved) {","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/write-commands.ts#L297-L333","documentation":"Error \"load-html: ${absolutePath} has ${ext} extension but content does not look like HTML. First bytes: ${hexDump}\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/write-commands.ts:315 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}