Opening local HTML file using Puppeteer

前端 未结 7 1924
梦谈多话
梦谈多话 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条回答
  •  Happy的楠姐
    2020-12-30 19:35

    If file is on local, using setContent will be better than goto

    var contentHtml = fs.readFileSync('C:/Users/compoundeye/test.html', 'utf8');
    await page.setContent(contentHtml);
    

    You can check performance between setContent and goto at here

提交回复
热议问题