-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miniflare Live Reload script not included if closing body
tag is missing
#70
Comments
Hey! 👋 The problem with using the import { Response } from "@miniflare/core";
import { HTMLRewriter } from "@miniflare/html-rewriter";
const rewriter = new HTMLRewriter().onDocument({
end(end) {
end.append("<script>alert('test')</script>", { html: true });
},
});
const input = new Response(
`<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Body</p>
</body>
</html>`,
{ headers: { "Content-Type": "text/html" } }
);
const output = rewriter.transform(input);
console.log(await output.text()); ...outputs...
Whilst this script still runs (at least in Firefox), it's definitely not in the right place. |
For what it's worth, per the spec:
(I admit it's a pretty minor issue, perhaps not worth putting it in the end events of both body and document, and only writing the latter if the former hasn't run.) |
It's correct that const input = new Response(
`<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Body`,
{ headers: { "Content-Type": "text/html" } }
); This is a valid HTML document – I removed the closing If you then have: rewriter.on('body', {
element(tag) {
tag.append('<p>NEW</p>', { html: true });
}
}); ...then you will never have the content added to the page. |
Hey! 👋 |
Using
miniflare@next
and--live-reload
, the Miniflare Live Reload script tag is only written when a</body>
tag exists. I'm not sure whether this is an HTMLRewriter implementation issue, but the script should probably be written from theend
event of the document handler.The text was updated successfully, but these errors were encountered: