feat(chromium): inject paint-callback polyfill when waitForExpression or waitForSelector is set

This commit is contained in:
Julien Neuhart
2026-04-24 12:14:52 +02:00
parent 8f711b0f99
commit 1c0ff24c4b
4 changed files with 229 additions and 0 deletions
@@ -195,6 +195,39 @@ Feature: /forms/chromium/convert/html
Wait delay > 2 seconds or expression window globalVar === 'ready' returns true.
"""
Scenario: POST /forms/chromium/convert/html (paint-callback polyfill fires rAF / ResizeObserver / IntersectionObserver when waitForExpression is set)
Given I have a default Gotenberg container
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s):
| files | testdata/paint-callbacks-html/index.html | file |
| waitForExpression | !!document.body.getAttribute('data-pdf-ready') | field |
| Gotenberg-Output-Filename | foo | header |
Then the response status code should be 200
Then the response header "Content-Type" should be "application/pdf"
Then there should be 1 PDF(s) in the response
Then there should be the following file(s) in the response:
| foo.pdf |
Then the "foo.pdf" PDF should have the following content at page 1:
"""
raf-fired
"""
Then the "foo.pdf" PDF should have the following content at page 1:
"""
ro-fired
"""
Then the "foo.pdf" PDF should have the following content at page 1:
"""
io-fired
"""
Scenario: POST /forms/chromium/convert/html (paint-callback polyfill skipped without a readiness signal)
Given I have a Gotenberg container with the following environment variable(s):
| LOG_LEVEL | debug |
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s):
| files | testdata/page-1-html/index.html | file |
Then the response status code should be 200
Then the Gotenberg container should log the following entries:
| paint-callbacks polyfill not requested |
Scenario: POST /forms/chromium/convert/html (Wait For Selector)
Given I have a default Gotenberg container
When I make a "POST" request to Gotenberg at the "/forms/chromium/convert/html" endpoint with the following form data and header(s):
@@ -0,0 +1,46 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Paint-driven callbacks</title>
<style>
body {
font-family: monospace;
padding: 20px;
}
#target {
width: 100px;
height: 100px;
background: #eee;
}
</style>
</head>
<body>
<p id="raf">raf-pending</p>
<p id="ro">ro-pending</p>
<p id="io">io-pending</p>
<div id="target">target</div>
<script>
requestAnimationFrame(function () {
document.getElementById("raf").textContent = "raf-fired";
});
var target = document.getElementById("target");
new ResizeObserver(function () {
document.getElementById("ro").textContent = "ro-fired";
}).observe(target);
new IntersectionObserver(function () {
document.getElementById("io").textContent = "io-fired";
}).observe(target);
// Signal Gotenberg to print after 2 s. Long enough for rAF / RO / IO
// to have fired when the polyfill is active; short enough to keep
// the test fast.
setTimeout(function () {
document.body.setAttribute("data-pdf-ready", "true");
}, 2000);
</script>
</body>
</html>