mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 01:22:43 +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.
36 lines
1.2 KiB
HTML
36 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
asyncTest(async (done) => {
|
|
internals.setTestTimeout(5000);
|
|
|
|
const httpServer = httpTestServer();
|
|
const body = `<!DOCTYPE html><body><div id="first">first</div>${" ".repeat(1700)}<div id="last">last</div>`;
|
|
const url = await httpServer.createEcho("GET", "/parser-streams-bytes", {
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type": "text/html",
|
|
},
|
|
body,
|
|
});
|
|
|
|
const frame = document.createElement("iframe");
|
|
let loaded = false;
|
|
let sawBodyBeforeLoad = false;
|
|
const interval = setInterval(() => {
|
|
if (!loaded && frame.contentDocument && frame.contentDocument.body && frame.contentDocument.body.children.length > 0)
|
|
sawBodyBeforeLoad = true;
|
|
}, 10);
|
|
|
|
frame.onload = () => {
|
|
loaded = true;
|
|
clearInterval(interval);
|
|
println(sawBodyBeforeLoad ? "PASS: iframe body parsed before load" : "FAIL: iframe body was not parsed before load");
|
|
done();
|
|
};
|
|
|
|
frame.src = `${url}?chunks=1500&chunk_delay_ms=250`;
|
|
document.body.appendChild(frame);
|
|
});
|
|
</script>
|