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?