Skip to content

Commit e93e147

Browse files
committed
playwright: use BROWSER_ADDRESS env var only
and remove the BROWSER_PATH
1 parent 77f5453 commit e93e147

File tree

3 files changed

+13
-59
lines changed

3 files changed

+13
-59
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ Lightpanda browser, but the code is not publicly available yet.
165165
### Running the benchmark
166166

167167
The `playwright/cdp.js` benchmark accepts multiple env vars to be configured.
168-
* `BROWSER_PATH` is the path to your browser implementing the CDP protocol. It can be either the path to a local binary or an URL (host:port) of a running browser. Default value is empty, which will launch the Google Chrome installed through Playwright.
168+
* `BROWSER_ADDRESS` is the address of the running browser listening the CDP protocol, by default `http://127.0.0.1:9222`.
169169
* `BASE_URL` is the base url of the running web reser to request, by default `http://127.0.0.1:1234`.
170170
* `RUNS` is the number of pages loaded by the benchmark, default is `100`.
171171

172172
`npm run bench-cdp` starts a playwright process
173173
instance and load the page to extract data 100 times.
174174

175175
```console
176-
$ BROWSER_PATH=127.0.0.1:9222 npm run bench-cdp
176+
$ npm run bench-cdp
177177
```
178178

179179
### Results
@@ -182,6 +182,12 @@ $ BROWSER_PATH=127.0.0.1:9222 npm run bench-cdp
182182

183183
We use Google Chrome version 123.0.6312.105.
184184

185+
You have to start the browser first.
186+
```console
187+
$ google-chrome --headless=new --disable-gpu --remote-debugging-port=9222
188+
```
189+
190+
Then you can run the benchmark.
185191
```console
186192
$ npm run bench-cdp
187193

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"description": "Lightpanda browser demo",
66
"main": "index.js",
77
"scripts": {
8-
"install-chrome": "npx playwright install chrome",
98
"ws": "go run ws/main.go",
109
"bench-cdp": "node playwright/cdp.js"
1110
},

playwright/cdp.js

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,12 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
import fs from 'fs';
1514

1615
// Import the Chromium browser into our scraper.
1716
import { chromium } from 'playwright';
1817

19-
// check if browser path if a local path or an URL
20-
let browserPath = process.env.BROWSER_PATH;
21-
let networkPath;
22-
if (browserPath) {
23-
24-
// not local path
25-
if (!fs.existsSync(browserPath)) {
26-
if (!browserPath.startsWith("http://")) {
27-
browserPath = "http://" + browserPath
28-
}
29-
const url = new URL(browserPath);
30-
networkPath = url.host;
31-
}
32-
}
33-
34-
// options passed to the browser
35-
let browserOptions = {};
36-
if (!networkPath) {
37-
38-
// chrome browser path
39-
if (browserPath) {
40-
browserOptions.executablePath = browserPath;
41-
}
42-
43-
// headless
44-
if (process.env.HEADLESS) {
45-
browserOptions.headless = process.env.HEADLESS === 'true';
46-
}
47-
}
18+
// browserAddress
19+
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'http://127.0.0.1:9222';
4820

4921
// web serveur url
5022
const baseURL = process.env.BASE_URL ? process.env.BASE_URL : 'http://127.0.0.1:1234';
@@ -57,32 +29,9 @@ const gstart = process.hrtime.bigint();
5729
// store all run durations
5830
let metrics = [];
5931

60-
let browser;
61-
if (networkPath) {
62-
63-
// Connect to an existing browser
64-
console.log("Connection to browser on " + networkPath + "...");
65-
66-
const resp = await fetch("http://" + networkPath + "/json/version");
67-
const version = await resp.json()
68-
const wsURL = version.webSocketDebuggerUrl;
69-
70-
browser = await chromium.connectOverCDP(wsURL);
71-
72-
} else {
73-
74-
// Launching a new browser
75-
if (browserPath) {
76-
console.log("Launching browser " + browserPath);
77-
} else {
78-
console.log("Launching browser");
79-
}
80-
81-
// We use headless: false
82-
// to be able to watch the browser window.
83-
browser = await chromium.launch(browserOptions);
84-
85-
}
32+
// Connect to an existing browser
33+
console.log("Connection to browser on " + browserAddress);
34+
const browser = await chromium.connectOverCDP(browserAddress);
8635

8736
for (var run = 1; run<=runs; run++) {
8837

0 commit comments

Comments
 (0)