Skip to content

Commit 99e9e53

Browse files
committed
switch between ws and http to connect to browser
1 parent 479f47c commit 99e9e53

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Lightpanda browser, but the code is not publicly available yet.
169169
### Running the benchmark
170170

171171
The `puppeteer/cdp.js` benchmark accepts multiple env vars to be configured.
172-
* `BROWSER_ADDRESS` is the address of the running browser listening the CDP protocol, by default `http://127.0.0.1:9222`.
172+
* `BROWSER_ADDRESS` is the address of the running browser listening the CDP protocol, by default `ws://127.0.0.1:9222`.
173173
* `BASE_URL` is the base url of the running web reser to request, by default `http://127.0.0.1:1234`.
174174
* `RUNS` is the number of pages loaded by the benchmark, default is `100`.
175175

@@ -193,7 +193,7 @@ $ /usr/bin/time -v google-chrome --headless=new --remote-debugging-port=9222
193193

194194
Then you can run the benchmark.
195195
```console
196-
$ npm run bench-puppeteer-cdp
196+
$ BROWSER_ADDRESS=http://127.0.0.1:9222 npm run bench-puppeteer-cdp
197197

198198
> [email protected] bench-puppeteer-cdp
199199
> node puppeteer/cdp.js

playwright/cdp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { chromium } from 'playwright';
1717

1818
// browserAddress
19-
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'http://127.0.0.1:9222';
19+
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222';
2020

2121
// web serveur url
2222
const baseURL = process.env.BASE_URL ? process.env.BASE_URL : 'http://127.0.0.1:1234';

puppeteer/cdp.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import puppeteer from 'puppeteer-core';
1717

1818
// ws address
19-
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'http://127.0.0.1:9222';
19+
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222';
2020

2121
// web serveur url
2222
const baseURL = process.env.BASE_URL ? process.env.BASE_URL : 'http://127.0.0.1:1234';
@@ -31,9 +31,14 @@ let metrics = [];
3131

3232
(async () => {
3333
// Connect to the browser and open a new blank page
34-
const browser = await puppeteer.connect({
35-
browserURL: browserAddress,
36-
});
34+
let opts = {};
35+
if (browserAddress.substring(0, 5) == 'ws://') {
36+
opts.browserWSEndpoint = browserAddress;
37+
} else {
38+
opts.browserURL = browserAddress;
39+
}
40+
41+
const browser = await puppeteer.connect(opts);
3742

3843
for (var run = 0; run<runs; run++) {
3944
// measure run time.

0 commit comments

Comments
 (0)