rendertron icon indicating copy to clipboard operation
rendertron copied to clipboard

[Feature] Add hooks for puppeteer page life cycle

Open gravi2 opened this issue 4 years ago • 4 comments

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.

gravi2 avatar Mar 03 '21 05:03 gravi2

@AVGP when you get a chance , please do review and let me know if you need any changes.

gravi2 avatar Mar 05 '21 21:03 gravi2

@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.

gravi2 avatar Mar 24 '21 06:03 gravi2

@AVGP just checking if you got a chance to review this PR and if you had any feedback?

gravi2 avatar Apr 14 '21 07:04 gravi2

@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.

gravi2 avatar May 06 '21 06:05 gravi2