Opening local HTML file using Puppeteer

前端 未结 7 1879
梦谈多话
梦谈多话 2020-12-30 19:04

Is it possible to open a local HTML file with headless Chrome using Puppeteer (without a web server)? I could only get it to work against a local server.

I found

7条回答
  •  一整个雨季
    2020-12-30 19:30

    You can use file-url to prepare the URL to pass to page.goto:

    const fileUrl = require('file-url');
    const puppeteer = require('puppeteer');    
    
    const browser = await puppeteer.launch();
    const page = await browser.newPage();   
     
    await page.goto(fileUrl('file.html'));    
     
    await browser.close();    
    

提交回复
热议问题