{"record":{"id":"996c4a264ff1cdd2","repo":"garrytan/gstack","slug":"load-html-from-file-html-too-large-max-byt","errorCode":null,"errorMessage":"load-html: --from-file html too large (> ${MAX_BYTES} bytes). Raise with GSTACK_BROWSE_MAX_HTML_BYTES=<N>.","messagePattern":"load-html: --from-file html too large \\(> (.+?) bytes\\)\\. Raise with GSTACK_BROWSE_MAX_HTML_BYTES=<N>\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/write-commands.ts","lineNumber":235,"sourceCode":"          fromFilePayload = { html: json.html, waitUntil: json.waitUntil };\n        } else if (args[i] === '--wait-until') {\n          const val = args[++i];\n          if (val !== 'load' && val !== 'domcontentloaded' && val !== 'networkidle') {\n            throw new Error(`Invalid --wait-until '${val}'. Must be one of: load, domcontentloaded, networkidle.`);\n          }\n          waitUntil = val;\n        } else if (args[i].startsWith('--')) {\n          throw new Error(`Unknown flag: ${args[i]}`);\n        } else if (!filePath) {\n          filePath = args[i];\n        }\n      }\n\n      // Inline HTML path: validate size + magic byte, then setContent directly.\n      if (fromFilePayload) {\n        const MAX_BYTES = parseInt(process.env.GSTACK_BROWSE_MAX_HTML_BYTES || '', 10) || (50 * 1024 * 1024);\n        if (Buffer.byteLength(fromFilePayload.html, 'utf8') > MAX_BYTES) {\n          throw new Error(\n            `load-html: --from-file html too large (> ${MAX_BYTES} bytes). ` +\n            'Raise with GSTACK_BROWSE_MAX_HTML_BYTES=<N>.'\n          );\n        }\n        const peek = fromFilePayload.html.trimStart();\n        if (!/^<[a-zA-Z!?]/.test(peek)) {\n          throw new Error('load-html: --from-file html does not start with a valid markup opener');\n        }\n        const finalWaitUntil = fromFilePayload.waitUntil ?? waitUntil;\n        await session.setTabContent(fromFilePayload.html, { waitUntil: finalWaitUntil });\n        return `Loaded HTML: (inline from --from-file, ${fromFilePayload.html.length} chars)`;\n      }\n\n      if (!filePath) throw new Error('Usage: browse load-html <file> [--wait-until load|domcontentloaded|networkidle] [--tab-id <N>]  |  load-html --from-file <payload.json> [--tab-id <N>]');\n\n      // Extension allowlist\n      const ALLOWED_EXT = ['.html', '.htm', '.xhtml', '.svg'];\n      const ext = path.extname(filePath).toLowerCase();","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/write-commands.ts#L217-L253","documentation":"Size cap at write-commands.ts:233-236. The html string in the --from-file payload is measured in UTF-8 bytes; if it exceeds MAX_BYTES the load is refused. The default cap is 50 MiB, overridable by the GSTACK_BROWSE_MAX_HTML_BYTES environment variable.","triggerScenarios":"A payload whose html field is larger than the cap — typically due to large embedded base64 images, inlined CSS/JS, or a generated report.","commonSituations":"HTML with many data: URIs; concatenated component snapshots; a generation pipeline that inlines all assets.","solutions":["Reduce the HTML: externalize large assets (images, scripts) to files or URLs","Raise the cap by setting GSTACK_BROWSE_MAX_HTML_BYTES=<bytes> before starting the browse server","Load the page from a served http://localhost URL instead of inlining"],"exampleFix":"// before — default 50 MiB cap exceeded\n// after — raise the cap when launching the browse server\nGSTACK_BROWSE_MAX_HTML_BYTES=$((100*1024*1024)) ./browse-server","handlingStrategy":"validation","validationCode":"function withinHtmlCap(html: string): boolean {\n  const cap = parseInt(process.env.GSTACK_BROWSE_MAX_HTML_BYTES || '', 10) || (50*1024*1024)\n  return Buffer.byteLength(html, 'utf8') <= cap\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Externalize large embedded assets (base64 images, inlined JS/CSS)","Raise GSTACK_BROWSE_MAX_HTML_BYTES only when genuinely needed","Prefer served http://localhost content for very large pages"],"tags":["load-html","size-limit","configuration","write-commands"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}