@usecanary/browser 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -9
- package/dist/cli.cjs +9280 -9268
- package/dist/cli.js +9278 -9266
- package/dist/cli.js.map +4 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,26 +1,108 @@
|
|
|
1
1
|
# @usecanary/browser
|
|
2
2
|
|
|
3
|
-
`canary-browser` — the browser-automation engine for
|
|
4
|
-
[
|
|
5
|
-
|
|
6
|
-
with a report
|
|
3
|
+
> `canary-browser` — the browser-automation engine for
|
|
4
|
+
> [Canary](https://github.com/usecanary/canary). Run sandboxed JavaScript against a real Chromium with
|
|
5
|
+
> persistent, named pages. This is **one-off** automation — nothing is recorded. For capture-enabled QA
|
|
6
|
+
> sessions with a `report.html`, use [`@usecanary/cli`](https://www.npmjs.com/package/@usecanary/cli).
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/@usecanary/browser)
|
|
9
|
+
[](https://github.com/usecanary/canary)
|
|
10
|
+
|
|
11
|
+
Scripts are plain async JavaScript in a QuickJS sandbox with a Playwright-like API — no `require`,
|
|
12
|
+
`process`, `fs`, or `fetch`; just a pre-connected `browser`, `console`, and a few file helpers. A
|
|
13
|
+
background daemon owns the real Chromium and starts automatically when needed. Use it to navigate,
|
|
14
|
+
click, fill, scrape, screenshot, or check a page — fast.
|
|
7
15
|
|
|
8
16
|
## Install
|
|
9
17
|
|
|
10
18
|
```bash
|
|
11
|
-
|
|
19
|
+
npm i -g @usecanary/browser # adds the `canary-browser` command
|
|
20
|
+
canary-browser install # one-time: download Chromium + runtime into ~/.canary
|
|
12
21
|
```
|
|
13
22
|
|
|
14
|
-
|
|
23
|
+
No global install? Use `npx @usecanary/browser …`.
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
15
26
|
|
|
16
27
|
```bash
|
|
28
|
+
# pipe a script via stdin
|
|
17
29
|
echo 'const p = await browser.getPage("main");
|
|
18
30
|
await p.goto("https://example.com");
|
|
19
|
-
console.log(await p.title());' |
|
|
31
|
+
console.log(await p.title());' | canary-browser run
|
|
32
|
+
|
|
33
|
+
# or run a file
|
|
34
|
+
canary-browser run ./script.js
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`run` exits non-zero if the script throws, so it composes in shell pipelines and CI.
|
|
38
|
+
|
|
39
|
+
## Commands
|
|
40
|
+
|
|
41
|
+
| Command | What it does |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `canary-browser run <FILE>` | Run a script file in the sandbox. |
|
|
44
|
+
| `canary-browser run` *(stdin)* | With no file, reads the script from stdin (`… \| canary-browser run`). |
|
|
45
|
+
| `canary-browser browsers` | List the daemon-managed browser instances currently running. |
|
|
46
|
+
| `canary-browser status` | Show daemon status. |
|
|
47
|
+
| `canary-browser install` | Install the embedded runtime (Chromium + Playwright + QuickJS) into `~/.canary`. |
|
|
48
|
+
| `canary-browser stop` | Stop the background daemon and every browser it's running. |
|
|
49
|
+
|
|
50
|
+
Run `canary-browser --help` for the full API reference and `canary-browser <command> --help` for
|
|
51
|
+
per-command detail.
|
|
52
|
+
|
|
53
|
+
## Global flags
|
|
54
|
+
|
|
55
|
+
| Flag | Effect |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `--browser <NAME>` | Use a specific named, daemon-managed browser instance (reuse state across runs). |
|
|
58
|
+
| `--connect [URL]` | Attach to an already-running Chrome instead of the daemon's Chromium. Bare `--connect` auto-detects; pass a CDP URL like `--connect=http://localhost:9222` to target one explicitly. |
|
|
59
|
+
| `--headless` | Launch the daemon-managed Chromium with no visible window. |
|
|
60
|
+
| `--ignore-https-errors` | Ignore HTTPS certificate errors. |
|
|
61
|
+
| `--timeout <SECONDS>` | Maximum script execution time (fails fast instead of hanging). |
|
|
62
|
+
| `--inject-script <PATH>` | Pre-load a JavaScript file on every page in the context (repeatable). |
|
|
63
|
+
| `-v, --verbose` | Verbose diagnostics on stderr. |
|
|
64
|
+
| `--json` | Machine-readable JSON diagnostics on stderr. |
|
|
20
65
|
|
|
21
|
-
|
|
66
|
+
### Drive your real, logged-in browser
|
|
67
|
+
|
|
68
|
+
`--connect` attaches to a Chrome you already have open — handy for flows behind a login. Start Chrome
|
|
69
|
+
with remote debugging, then connect:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# launch (or relaunch) Chrome with a debugging port, then:
|
|
73
|
+
canary-browser --connect run ./scrape-dashboard.js
|
|
22
74
|
```
|
|
23
75
|
|
|
24
|
-
|
|
76
|
+
## Scripting
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
const page = await browser.getPage("main"); // named, persistent page
|
|
80
|
+
await page.goto("https://news.ycombinator.com", { waitUntil: "domcontentloaded" });
|
|
81
|
+
|
|
82
|
+
const titles = await page.evaluate(() =>
|
|
83
|
+
[...document.querySelectorAll("span.titleline > a")].slice(0, 10).map((a) => a.textContent)
|
|
84
|
+
);
|
|
85
|
+
console.log(JSON.stringify(titles)); // stdout is the result
|
|
86
|
+
|
|
87
|
+
await saveScreenshot(await page.screenshot(), "hn.png"); // saved under ~/.canary/tmp/
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- **Pages** — `browser.getPage(name)`, `browser.newPage()`, `browser.listPages()`,
|
|
91
|
+
`browser.closePage(name)`. Pages are full Playwright `Page`s (`goto`, `click`, `fill`, `locator`,
|
|
92
|
+
`evaluate`, `getByRole`, `waitForSelector`, `screenshot`, …).
|
|
93
|
+
- **Files** (sandboxed to `~/.canary/tmp/`) — `saveScreenshot(buffer, name)`, `writeFile(name, data)`,
|
|
94
|
+
`readFile(name)`.
|
|
95
|
+
- **Limits** — no module system, no Node APIs; CPU and wall-clock are bounded (raise the budget with
|
|
96
|
+
`--timeout`). Values crossing `evaluate` must be JSON-serializable.
|
|
97
|
+
|
|
98
|
+
Full reference:
|
|
99
|
+
[canary-scripting](https://github.com/usecanary/canary/blob/main/skills/canary-scripting/references/REFERENCE.md).
|
|
100
|
+
|
|
101
|
+
## Related packages
|
|
102
|
+
|
|
103
|
+
- [`@usecanary/cli`](https://www.npmjs.com/package/@usecanary/cli) — record verifiable QA **sessions**
|
|
104
|
+
(trace/video/HAR/console) and render a report.
|
|
105
|
+
- [`@usecanary/ui`](https://www.npmjs.com/package/@usecanary/ui) — browse recorded sessions.
|
|
106
|
+
- [`create-canary`](https://www.npmjs.com/package/create-canary) — `npm create canary` guided setup.
|
|
25
107
|
|
|
26
108
|
MIT · [source](https://github.com/usecanary/canary)
|