[Feature] Add hooks for puppeteer page life cycle
Why
I noticed that Rendertron currently does not handle CSSOM that are injected on the page using insertRule. As these CSS rules are added to the browsers memory and do not make it in DOM, Rendertron can't serialize/save these styles in the generated snapshot.
Examples of the issue
There are few reports of these kind of issues #291 , styled-components#2577, prerender#574.
Changes proposed
This PR proposes to add puppeteer config section to the config file. The config will support evaluateOnNewDocument and beforeSerialize
"puppeteer": {
"evaluateOnNewDocument": "SC_DISABLE_SPEEDY = true;",
"beforeSerialize": "./test-resources/cssom-to-styles.js"
}
puppeteer config
Currently only supports:
-
evaluateOnNewDocument- inline script/function that is invoked after the document was created but before any of its scripts were run. You can use this as a hook to initialize/bootstrap any custom logic/state needed by the page. See puppeteer.evaluateOnNewDocument -
beforeSerialize- path to a custom JS script that will be executed before the page is serialized by rendertron. The path is relative to rendertron root folder or can be absolute path.
Potential future extension
With the puppeteer config section, it will be possible to expose/support more puppeteer configurations/customizations in future.
README and Docs
Included in this PR also are the updates to the README and configuration.md files.
Test cases
Added 2 test cases to validate the working of evaluateOnNewDocument and beforeSerialize configuration.
@AVGP when you get a chance , please do review and let me know if you need any changes.
@AVGP bumping this up to make sure it does not get lost in the dependabot PRs :). Please do review it when you get a chance.
@AVGP just checking if you got a chance to review this PR and if you had any feedback?
@AVGP I have rebased my PR to the latest master changes. But now looks like the 3 checks (related to ec2 cache) are failing due to the missing google-cloud-sdk-datastore-emulator package. My PR does not have any changes relevant to these. I am still looking but I think these checks maybe failing on "main" too.