Skip to content

Commit 22a6acc

Browse files
committed
readme: add a quick start section
1 parent 277c97a commit 22a6acc

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,73 @@ NOTE: There are hundreds of Web APIs. Developing a browser (even just for headle
7070

7171
You can also follow the progress of our Javascript support in our dedicated [zig-js-runtime](https://github.com/lightpanda-io/zig-js-runtime#development) project.
7272

73-
## Install
73+
## Quick start
7474

75-
We provide [nighly builds](https://github.com/lightpanda-io/browser/releases/tag/nightly) for Linux x86_64 and MacOS aarch64.
75+
### Install from the nightly builds
76+
77+
You can download the last binary from the [nightly
78+
builds](https://github.com/lightpanda-io/browser/releases/tag/nightly) for
79+
Linux x86_64 and MacOS aarch64.
80+
81+
```console
82+
# Download the binary
83+
$ wget https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-x86_64-linux
84+
$ chmod a+x ./lightpanda-x86_64-linux
85+
$ ./lightpanda-x86_64-linux -h
86+
usage: ./lightpanda-x86_64-linux [options] [URL]
87+
88+
start Lightpanda browser
89+
90+
* if an url is provided the browser will fetch the page and exit
91+
* otherwhise the browser starts a CDP server
92+
93+
-h, --help Print this help message and exit.
94+
--host Host of the CDP server (default "127.0.0.1")
95+
--port Port of the CDP server (default "9222")
96+
--timeout Timeout for incoming connections of the CDP server (in seconds, default "3")
97+
--dump Dump document in stdout (fetch mode only)
98+
```
99+
100+
### Dump an URL
101+
102+
```console
103+
$ ./lightpanda-x86_64-linux --dump https://lightpanda.io
104+
info(browser): GET https://lightpanda.io/ http.Status.ok
105+
info(browser): fetch script https://api.website.lightpanda.io/js/script.js: http.Status.ok
106+
info(browser): eval remote https://api.website.lightpanda.io/js/script.js: TypeError: Cannot read properties of undefined (reading 'pushState')
107+
<!DOCTYPE html>
108+
```
109+
110+
### Start a CDP server
111+
112+
```console
113+
$ ./lightpanda-x86_64-linux --host 127.0.0.1 --port 9222
114+
info(websocket): starting blocking worker to listen on 127.0.0.1:9222
115+
info(server): accepting new conn...
116+
```
117+
118+
Once the CDP server started, you can run a Puppeteer script by configuring the
119+
`browserWSEndpoint`.
120+
121+
```js
122+
'use scrict'
123+
124+
import puppeteer from 'puppeteer-core';
125+
126+
// use browserWSEndpoint to pass the Lightpanda's CDP server address.
127+
const browser = await puppeteer.connect({
128+
browserWSEndpoint: "ws://127.0.0.1:9222",
129+
});
130+
131+
// The rest of your script remains the same.
132+
const context = await browser.createBrowserContext();
133+
const page = await context.newPage();
134+
135+
await page.goto('https://wikipedia.com/');
136+
137+
await page.close();
138+
await context.close();
139+
```
76140

77141
## Build from sources
78142

0 commit comments

Comments
 (0)