{"record":{"id":"1e3825fc080b904f","repo":"ramensoftware/windhawk","slug":"the-webview-template-has-no-body-tag-to-inject-the-webview","errorCode":null,"errorMessage":"The webview template has no <body> tag to inject the webview parameters into","messagePattern":"The webview template has no <body> tag to inject the webview parameters into","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/windhawk-vscode/src/extension.ts","lineNumber":2218,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t}, 0);\n\t\t\t});\n\t\t\twindow.addEventListener('focus', () => {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tif (lastFocused && (!document.activeElement || document.activeElement === document.body)) {\n\t\t\t\t\t\tlastFocused.focus();\n\t\t\t\t\t}\n\t\t\t\t}, 0);\n\t\t\t});\n\t\t})();</script>\n\t`);\n\n\tconst dataParams = bodyDataParams ? ` data-params=\"${escapeHtml(JSON.stringify(bodyDataParams))}\"` : '';\n\tconst dataVscodeContext = ` data-vscode-context='{\"preventDefaultContextMenuItems\": true}'`;\n\n\tconst bodyTagRegex = /<body([^>]*)>/;\n\tif (!bodyTagRegex.test(html)) {\n\t\tthrow new Error('The webview template has no <body> tag to inject the webview parameters into');\n\t}\n\n\thtml = html.replace(bodyTagRegex, (_match, bodyAttributes: string) =>\n\t\t`<body data-content=\"${bodyDataContent}\"${dataParams}${dataVscodeContext}${bodyAttributes}>`);\n\n\treturn html;\n}\n","sourceCodeStart":2200,"sourceCodeEnd":2226,"githubUrl":"https://github.com/ramensoftware/windhawk/blob/61d99ed8e182e1af1b60109612b6763ad1b4b74e/src/windhawk-vscode/src/extension.ts#L2200-L2226","documentation":"The extension builds webview HTML from a template file and injects runtime parameters by rewriting the template's <body> tag. Before replacing, it tests the HTML with /<body([^>]*)>/ and throws this error when no <body> tag exists. The throw prevents silently producing a webview missing data attributes (data-content, data-params, data-vscode-context) that the webview scripts rely on.","triggerScenarios":"Calling the webview HTML builder (getWebviewContent-style function at src/windhawk-vscode/src/extension.ts:2218) with a template whose HTML lacks a <body> element — e.g. the template file was edited to remove the body tag, is an XML/SVG fragment, uses uppercase/malformed markup not matched by the case-sensitive lowercase regex, or the wrong template path was loaded.","commonSituations":"A contributor refactored the webview template and dropped <body> (e.g. switching to a framework-style shell or a snippet that renders body-less HTML); a template placeholder substitution accidentally consumed the tag; or a custom/older template in the repo no longer matches the extension's expectation.","solutions":["Open the webview template file used by the extension and ensure it contains a literal <body ...> tag (lowercase, with a closing >).","If the template uses uppercase <BODY> or unusual formatting, normalize it to a standard lowercase <body> tag so /<body([^>]*)>/ matches.","Verify the correct template file path is being loaded (not a partial/fragment file) before calling the injection function.","After editing the template, reload the VS Code window / restart the extension host so the new template is read."],"exampleFix":"// before (template.html)\n<div id=\"app\"></div>\n// after (template.html)\n<html>\n  <body>\n    <div id=\"app\"></div>\n  </body>\n</html>","handlingStrategy":"validation","validationCode":"const html = await loadTemplate(path);\nif (!/<body[^>]*>/.test(html)) {\n  throw new Error(`Template ${path} is missing a <body> tag`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const html = getWebviewHtml(template);\n} catch (e) {\n  if (e.message.includes('no <body> tag')) {\n    vscode.window.showErrorMessage('Webview template is invalid; check that it contains a <body> tag.');\n  }\n}","preventionTips":["Keep webview templates as full HTML documents with a literal lowercase <body> tag.","Add a build-time or unit test asserting /<body[^>]*>/ matches every shipped webview template.","Never let template substitutions replace or consume the <body> tag itself."],"tags":["vscode","webview","html-template"],"backgroundTag":"internal-invariant-violation","analyzedSha":"61d99ed8e182e1af1b60109612b6763ad1b4b74e","analyzedAt":"2026-09-12T14:02:41.115Z","contentChangedAt":"2026-09-12T14:02:41.115Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}