本文主要介绍Node.js中,安装运行Firefox 火狐浏览器版 puppeteer的方法,以及相关的示例代码。

1、安装Firefox puppeteer

npm i puppeteer-firefox

2、使用运行示例代码

const puppeteerFirefox = require('puppeteer-firefox');
(async () => {
    const test = async browser => {
        const page = await browser.newPage();
        await page.setViewport({
            width: 1280,
            height: 800
        });
        await page.goto('https://www.bbc.com/news');   
        await page.hover('#nw-c-most-read-heading__title');
        await page.screenshot({ path: 'bcc-most-read.png' })
        await browser.close();
    }
    const firefox = await puppeteerFirefox.launch({
        headless: false,
        slowMo: 50
    });
    await test(firefox);
})();

推荐文档