mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
Introduce IncrementalDocumentParser, which streams the response body through a TextCodec::StreamingDecoder into the HTMLTokenizer one chunk at a time. The tokenizer pauses when it runs out of input and resumes once the next chunk is appended; when the body closes we close the tokenizer's input stream so it can finish the parse. DocumentLoading routes HTML responses through the new parser instead of buffering the full body before handing it to HTMLParser.
29 lines
1.1 KiB
HTML
29 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
asyncTest(async (done) => {
|
|
internals.setTestTimeout(5000);
|
|
|
|
const httpServer = httpTestServer();
|
|
const stylePrefix = `<!DOCTYPE html><head><style>${" ".repeat(1700)}`;
|
|
const body = `${stylePrefix}#target { color: rgb(1, 2, 3); }</style></head><body><div id="target">styled</div><script>window.onload = () => parent.postMessage({ color: getComputedStyle(document.getElementById("target")).color, text: document.getElementById("target").textContent }, "*");<\/script>`;
|
|
const url = await httpServer.createEcho("GET", "/parser-streams-style-split", {
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type": "text/html",
|
|
},
|
|
body,
|
|
});
|
|
|
|
const frame = document.createElement("iframe");
|
|
window.addEventListener("message", event => {
|
|
println(event.data.color);
|
|
println(event.data.text);
|
|
done();
|
|
}, { once: true });
|
|
|
|
frame.src = `${url}?chunks=${stylePrefix.length}&chunk_delay_ms=100`;
|
|
document.body.appendChild(frame);
|
|
});
|
|
</script>
|