您可以通过将puppeteer与browserify结合使用来从常规浏览器中运行铬吗?

时间:2018-08-15 12:51:07

标签: webpack requirejs browserify puppeteer

我正在尝试通过常规浏览器中的buttonclick运行Puppeteer脚本。因此,我使用browserify打包了我的应用程序,以便可以在浏览器中使用require('puppeteer'),就像我们可以对其他使用require()的模块一样。

我是通过在相关目录中的终端上运行“ browserify main.js -o bundle.js”来完成此操作的,就像处理其他browserify项目一样。但是,使用Puppeteer打包后运行脚本时会出现以下错误:

Uncaught (in promise) TypeError: Cannot read property 'bind' of undefined
at Object.52../helper (bundle.js:8800)
at o (bundle.js:1)
at bundle.js:1
at Object. (bundle.js:11817)
at Object.62../Browser (bundle.js:12161)
at o (bundle.js:1)
at bundle.js:1
at Object.68../BrowserFetcher (bundle.js:14534)
at o (bundle.js:1)
at bundle.js:1

任何想法可能是什么原因造成的? 还是与其他模块相反,使用puppeteer不可能做到这一点?

您可以在此处找到非常简短的代码:

https://github.com/dutchsparks/browserifypuppeteer

1 个答案:

答案 0 :(得分:1)

不可能在浏览器中运行Puppeteer-此程序包仅在节点环境中有效。您可以使用Puppeteer设置后端,并通过浏览器向其发送请求。