admin管理员组文章数量:1336631
I am trying to use puppeteer with a local script file.
I get the script file to load when I host the file and use addScriptTag() with the localhost address. This is not ideal. I need to use the local file directly from the path. The current working directory is /maps in this case. I set the relative path as path in the options of the addScriptTag() function but the code just goes dark on me at this stage. There is no error and no stepping into anything.
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();
})();
Any help will be wele as I find the puppetteer documentation increasingly frustrating and there aren't (m)any working examples as of now.
I am trying to use puppeteer with a local script file.
I get the script file to load when I host the file and use addScriptTag() with the localhost address. This is not ideal. I need to use the local file directly from the path. The current working directory is /maps in this case. I set the relative path as path in the options of the addScriptTag() function but the code just goes dark on me at this stage. There is no error and no stepping into anything.
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();
})();
Any help will be wele as I find the puppetteer documentation increasingly frustrating and there aren't (m)any working examples as of now.
Share Improve this question asked Oct 16, 2017 at 15:56 Dennis BauszusDennis Bauszus 1,8024 gold badges21 silver badges50 bronze badges1 Answer
Reset to default 4It's a version problem. This method was only introduced in the latest update 0.12 from yesterday. I installed puppeteer the day before. Meh!
https://github./GoogleChrome/puppeteer/issues/949
本文标签: javascriptHow to use addScriptTag() with local file path in PuppeteerStack Overflow
版权声明:本文标题:javascript - How to use addScriptTag() with local file path in Puppeteer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742408163a2469246.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论