3

This is a similar question to Opening local html file using puppeteer, except that that one is using regular Puppeteer (headless Chrome) and this one is using the Firefox version, and I care about references to other local files.

I'm trying to open a local HTML file with puppeteer-firefox. Here's some example code:

const pptrFirefox = require('puppeteer-firefox');
const path = require('path');

(async () => {
  const browser = await pptrFirefox.launch();
  const page = await browser.newPage();
  await page.goto(`file:${path.join(__dirname, 'template.html')}`);
  await page.screenshot({path: 'example.png'});
  await browser.close();
})();

This hangs at the page.screenshot line.

I've tried this with file: and file:// as the prefix of the path. It's the same either way.

It works fine if the URL is something remote like https://example.com instead.

My first idea for a workaround was to get a string of the HTML I want, by using a templating library or just readFile, and then passing this to page.setContent. This works, but then the page won't load its assets such as relative paths to local image files. I've tried prefixing those asset paths with the full file: path; no difference.

I swapped out puppeteer-firefox for the regular puppeteer, and it works.

Will headless Firefox simply refuse to load local files? Or am I doing something wrong? Or is there a bug in puppeteer-firefox?

tremby
  • 9,541
  • 4
  • 55
  • 74
  • In your `page.goto` line, you are missing a closing bracket `}`. Apart from that, your code is working fine for me (Windows). – Thomas Dondorf Mar 07 '19 at 18:26
  • I think my comment got missing :/ That feature is still failing in Firefox, see https://github.com/GoogleChrome/puppeteer/blob/1623bef26452f5f90c899ca159f237e074c765b0/test/network.spec.js#L706, You'll have to wait for it. – hardkoded Mar 07 '19 at 18:52
  • @ThomasDondorf that was a typo for my example code which doesn't exist in my application; sorry about that. You say it's working for you on Windows? You're definitely using the Firefox version of puppeteer? – tremby Mar 07 '19 at 19:29
  • @hardkoded: I don't fully understand the code you linked. Are you saying the feature isn't complete yet? I expected to see something on https://aslushnikov.github.io/ispuppeteerfirefoxready/ but I don't see where this feature would be. – tremby Mar 07 '19 at 19:31
  • @tremby Sorry, I was wrong. `page.screenshot` is not working for me. The browser opens and navigates to the file (I checked it in headful mode), but it is actually stuck when `page.screenshot` is called. – Thomas Dondorf Mar 07 '19 at 19:52

0 Answers0