Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puppeteer screenshot works, but not penthouse #353

Open
davidwebca opened this issue Dec 12, 2022 · 2 comments
Open

Puppeteer screenshot works, but not penthouse #353

davidwebca opened this issue Dec 12, 2022 · 2 comments

Comments

@davidwebca
Copy link

davidwebca commented Dec 12, 2022

Penthouse is currently unable to see the full HTML rendered by my Vue app and thus doesn't provide the correct critical css.

The screenshot returned by penthouse is blank which lead me to believe it doesn't wait long enough for my JS to fully initialize. I added "renderWaitTime" and regardless, it doesn't work.

I then tried loading puppeteer manually, the version installed with penthouse, to get a screenshot and see what the browser "sees" and it works properly. I used this code to make the screenshot teset:

import puppeteer from 'puppeteer';
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  page.setViewport({
    width: 1920,
    height: 1080
  });
  await page.goto('http://mywebsite.com');
  await delay(5000);
  await page.screenshot({path: 'screenshottest.png'});
  await browser.close();
})();

Here's the config I'm passing down to penthouse.

renderWaitTime: 5000,
blockJSRequests: false,
keepLargerMediaQueries: true,
width: 1920,
height: 1080,
screenshots: {
  basePath: 'homepage',
  type: 'jpeg',
  quality: 80
}
@davidwebca
Copy link
Author

davidwebca commented Dec 12, 2022

I found a trail. Penthouse ignores media="print", but the plugin for Craft CMS that I use (craft-plugin-vite) uses the common print to onload="this.media='all'" stylesheet preload method.

So the "print" style gets thrown away before the stylehseet has a change of loading at all. Penthouse probably should wait that the stylesheet has loaded to check its media attribute.

Just adding this detail if anyone stumbles onto this from a craft project:
For now, the craft vite plugin allows passing a 2nd attribute to the craft.vite.script function to prevent the async loading in the twig, so I added an env var to prevent it locally only. {{ craft.vite.script("src/main.js", getenv('CRAFT_VITE_ASYNC_CSS') ? true : false) }}

@davidwebca
Copy link
Author

Well well. I use rollup-plugin-critical which uses critical which uses penthouse and critical is wrongly passing down the HTML to compare instead of letting penthouse doing its job. :| I apologize for that. Probably had nothing to do with the loading swap I mentionned earlier -_-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant