Connecting Browsers in Puppeteer

雨燕双飞 提交于 2020-01-23 16:39:07

问题


Is it possible to connect a browser to puppeteer without instantiating it in puppeteer? For example, running an instance of chromium like a regular user and then connecting that to an instance of puppeteer in code?


回答1:


The answer is Yes and No.

You can connect to an existing using the connect function:

const browserURL = 'http://127.0.0.1:21222';
const browser = await puppeteer.connect({browserURL});

But, if you want to use those 2 lines you need to launch Chrome with the "--remote-debugging-port=21222 argument.




回答2:


Yes, you can. I see in the document have field: executablePath

By default, Puppeteer downloads and uses a specific version of Chromium so its API is guaranteed to work out of the box. To use Puppeteer with a different version of Chrome or Chromium, pass in the executable's path when creating a Browser instance:

const browser = await puppeteer.launch({executablePath: '/path/to/Chrome'});


来源:https://stackoverflow.com/questions/55096771/connecting-browsers-in-puppeteer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!