Connecting Browsers in Puppeteer
10,511
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.
Author by
Jak
Updated on June 14, 2022Comments
-
Jak almost 2 years
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?
-
Jak about 5 yearsThanks, very helpful. How about if I want to launch with Chromium? Would I still have to launch with any added arguments?
-
hardkoded about 5 years@Jak yes, you always need to tell Chrome that he has to "open the doors" for remote debugging.
-
Jak about 5 yearsAlright that makes sense. I am having some trouble finding any sort of documentation to help identify the appropriate browserURL for my instance of Chrome. Do you have any suggestions?
-
hardkoded about 5 years@Jak If you launch chromium with the flag
--remote-debugging-port=21222
, you will know that thebrowserURL
(not the browserWSEndpoint) will behttp://127.0.0.1:21222
-
Jason Zhou about 4 yearsI opened chromium with command
chromium-browser --remote-debugging-port=21222
. but when connect, I get an errorError: connect ECONNREFUSED 127.0.0.1:21222
. -
Taha Daboussi almost 3 yearshi , i wonder if there is a way to automatically for puppeteer to find an available port and connect to it ?