Den*_*zus 5 javascript puppeteer
我正在尝试将 puppeteer 与本地脚本文件一起使用。
当我托管文件并使用addScriptTag()和本地主机地址时,我会加载脚本文件。这并不理想。我需要直接从路径使用本地文件。在本例中,当前工作目录是 /maps。我在 addScriptTag() 函数的选项中将相对路径设置为路径,但在这个阶段代码对我来说只是变黑了。没有错误,也没有介入任何事情。
console.log(`Current directory: ${process.cwd()}`);
// C:\Users\dbauszus\Documents\GitHub\maps
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(jsr.templates('./views/report.html').render(), {waitUntil: 'load'});
// works with an url to the same file.
// await page.addScriptTag('http://localhost:3000/maps/js/build/report_bundle.js');
// path for js file on windows C:\Users\dbauszus\Documents\GitHub\maps\public\js\build\report_bundle.js
await page.addScriptTag({path: 'public\\js\\build\\report_bundle.js'});
await page.screenshot({path: 'example.png'});
await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)
任何帮助都会受到欢迎,因为我发现木偶文档越来越令人沮丧,而且到目前为止还没有任何工作示例。
是版本问题。这个方法是在昨天最新的0.12更新中才引入的。我前一天安装了 puppeteer。嗯!
https://github.com/GoogleChrome/puppeteer/issues/949
| 归档时间: |
|
| 查看次数: |
9272 次 |
| 最近记录: |