ramensoftware/windhawk · error

The webview template has no

Error message

The webview template has no <body> tag to inject the webview parameters into

What it means

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.

Solutions

  1. Open the webview template file used by the extension and ensure it contains a literal <body ...> tag (lowercase, with a closing >).
  2. If the template uses uppercase <BODY> or unusual formatting, normalize it to a standard lowercase <body> tag so /<body([^>]*)>/ matches.
  3. Verify the correct template file path is being loaded (not a partial/fragment file) before calling the injection function.
  4. After editing the template, reload the VS Code window / restart the extension host so the new template is read.

Example fix

// before (template.html)
<div id="app"></div>
// after (template.html)
<html>
  <body>
    <div id="app"></div>
  </body>
</html>
Defensive patterns

Strategy: validation

Validate before calling

const html = await loadTemplate(path);
if (!/<body[^>]*>/.test(html)) {
  throw new Error(`Template ${path} is missing a <body> tag`);
}

Try / catch

try {
  const html = getWebviewHtml(template);
} catch (e) {
  if (e.message.includes('no <body> tag')) {
    vscode.window.showErrorMessage('Webview template is invalid; check that it contains a <body> tag.');
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of ramensoftware/windhawk@61d99ed8e1 (2026-09-12). Data as JSON: /api/errors/1e3825fc080b904f. Report an issue: GitHub.

Appendix: source

Thrown at src/windhawk-vscode/src/extension.ts:2218

					}
				}, 0);
			});
			window.addEventListener('focus', () => {
				setTimeout(() => {
					if (lastFocused && (!document.activeElement || document.activeElement === document.body)) {
						lastFocused.focus();
					}
				}, 0);
			});
		})();</script>
	`);

	const dataParams = bodyDataParams ? ` data-params="${escapeHtml(JSON.stringify(bodyDataParams))}"` : '';
	const dataVscodeContext = ` data-vscode-context='{"preventDefaultContextMenuItems": true}'`;

	const bodyTagRegex = /<body([^>]*)>/;
	if (!bodyTagRegex.test(html)) {
		throw new Error('The webview template has no <body> tag to inject the webview parameters into');
	}

	html = html.replace(bodyTagRegex, (_match, bodyAttributes: string) =>
		`<body data-content="${bodyDataContent}"${dataParams}${dataVscodeContext}${bodyAttributes}>`);

	return html;
}

View on GitHub (pinned to 61d99ed8e1)