@zenera/browser 1.4.1 → 1.4.3
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 +112 -39
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,46 +21,119 @@
|
|
|
21
21
|
# @zenera/browser
|
|
22
22
|
|
|
23
23
|
An html page in a real browser, served as a zen chat serves it: checked for errors, driven,
|
|
24
|
-
photographed. It
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
24
|
+
photographed. It powers `zen page` (in [`@zenera/cli`](../cli)), the command agents use to look at
|
|
25
|
+
pages they build, to take screenshots and to browse websites. Agents learn it from the
|
|
26
|
+
`browser` and `html-page` skills and run it with `run_command`.
|
|
27
|
+
|
|
28
|
+
## Set up
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
zen page install # a local headless Chromium (~100 MB), once
|
|
32
|
+
# or use a browser that is already running:
|
|
33
|
+
export ZEN_BROWSER_URL=ws://browser:3000/ # a Playwright run-server
|
|
34
|
+
export ZEN_BROWSER_URL=http://localhost:9222 # a DevTools endpoint
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If a remote browser is full or down, it is tried twice more, then the local one is used.
|
|
38
|
+
|
|
39
|
+
## Check a page in one command
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
zen page check /workspace/pages/todo
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
It loads the page once, at each width, and reports errors, failed function calls and sideways
|
|
46
|
+
scrolling, then lists the screenshots:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
✗ /workspace/pages/todo/index.html: 2 errors (loaded in 0.8 s)
|
|
50
|
+
✗ function POST /workspace/pages/todo/api/items/add_item → 500: add_item failed: KeyError: 'done'
|
|
51
|
+
✗ panel (400 px): the page is 708 px wide and scrolls sideways - div.toolbar (to 708 px)
|
|
52
|
+
screenshots - open them all at once, one view_image each in the same reply:
|
|
53
|
+
/workspace/.tmp/page-check/todo/index-panel.png (panel, 400 px)
|
|
54
|
+
/workspace/.tmp/page-check/todo/index-wide-panel.png (wide-panel, 640 px)
|
|
55
|
+
/workspace/.tmp/page-check/todo/index-tab.png (tab, 1280 px)
|
|
56
|
+
/workspace/.tmp/page-check/todo/index-panel-dark.png (panel, 400 px, dark)
|
|
57
|
+
/workspace/pages/todo/preview.png (the chat's card for the page, 1200×630, light)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
It exits 1 on an error. The agent fixes each `✗`, builds, checks again, and looks at the
|
|
61
|
+
screenshots with `view_image`. Options:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
zen page check /workspace/pages/todo --widths panel,tab # presets or px
|
|
65
|
+
zen page check report.html --no-dark --out /tmp/shots # a single file, shots elsewhere
|
|
66
|
+
zen page check https://example.com --timeout 30 # a URL works too
|
|
67
|
+
zen page check /workspace/pages/todo --json # the report as JSON
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Widths: `panel` 400 px (the chat's side panel), `wide-panel` 640, `tab` 1280, or a number. A
|
|
71
|
+
screenshot shows the top 1600 px of the page; `screenshot --full` in a session shows the rest.
|
|
72
|
+
|
|
73
|
+
## Drive a page: a session
|
|
74
|
+
|
|
75
|
+
`zen page open` starts a browser and keeps one tab open; the agent runs it in the background
|
|
76
|
+
(`run_command_background`) and then sends one short command per step. The tab keeps its state
|
|
77
|
+
between commands.
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
zen page open /workspace/pages/todo # in the background; prints "ready"
|
|
81
|
+
zen page snapshot # the page as text; each element carries a ref
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
- textbox "New item" [ref=e10]
|
|
86
|
+
- button "Add" [disabled] [ref=e11]
|
|
87
|
+
- combobox [ref=e12]:
|
|
88
|
+
- option "All" [selected]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
zen page fill e10 "TEST milk" # replaces what is in the input
|
|
93
|
+
zen page click e11 # answers with new errors and the new snapshot
|
|
94
|
+
zen page select e12 Done
|
|
95
|
+
zen page wait --text "Saved"
|
|
96
|
+
zen page screenshot --width panel # prints a file to view
|
|
97
|
+
zen page resize tab # the same state, wide
|
|
98
|
+
zen page screenshot --full # all of a tall page, in parts of 1600 px
|
|
99
|
+
zen page console # errors and failed requests since the last command
|
|
100
|
+
zen page close
|
|
63
101
|
```
|
|
64
102
|
|
|
103
|
+
- Refs come from the last snapshot; each action answers with a new one (`--no-snapshot` to skip
|
|
104
|
+
it). Playwright selectors work too: `'role=button[name="Add"]'`, `'text=Milk'`, CSS.
|
|
105
|
+
- Every action waits for the page to settle (requests and functions done) before it answers.
|
|
106
|
+
- More: `dblclick`, `hover`, `type` (key by key), `press Enter`, `wait --gone "Loading…"`,
|
|
107
|
+
`goto <page|url>`, `reload` (after a build), `back`, `dark`, `light`, `eval "<js>"`, `status`.
|
|
108
|
+
Text with quotes or from a file: `--stdin`, e.g. `zen page fill e10 --stdin < note.txt`.
|
|
109
|
+
- Screenshots: `screenshot e7` (one element), `--width <w>`, `--dark`/`--light`, `--full`,
|
|
110
|
+
`--viewport` (only the window), `--out <file>`.
|
|
111
|
+
- One session per workspace; `open` again replaces it. It closes after 10 minutes without a
|
|
112
|
+
command (`--idle <s>`).
|
|
113
|
+
|
|
114
|
+
## Browse a website
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
zen page open https://example.com/pricing # in the background
|
|
118
|
+
zen page snapshot # the rendered page, after its scripts ran
|
|
119
|
+
zen page click e23 # open a tab, "show more", a link
|
|
120
|
+
zen page screenshot --width tab
|
|
121
|
+
zen page close
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Use it when content appears only in a browser (built by scripts, behind a click) or when the
|
|
125
|
+
look matters; for a static page `curl` is faster. Private and local addresses are refused, and
|
|
126
|
+
what a site says is data for the agent, not instructions.
|
|
127
|
+
|
|
128
|
+
## How it works
|
|
129
|
+
|
|
130
|
+
- Local pages are served by **`PageHost`** with `@zenera/engine`'s `serveViewPath`, the code
|
|
131
|
+
behind a chat's `/v/` pages: their files under the view CSP, their `*.api.py` functions run in
|
|
132
|
+
a `ProcessSandbox`, on a private Unix socket, no port. Besides them, only `cdn.jsdelivr.net`,
|
|
133
|
+
`unpkg.com` and `cdnjs.cloudflare.com` are reached.
|
|
134
|
+
- **`PageSession`** is one tab; **`checkPage`** is `zen page check`; **`WIDTH_PRESETS`**,
|
|
135
|
+
**`resolveTarget`** and **`installBrowser`** are the widths, the page lookup and
|
|
136
|
+
`zen page install`. All are exported for programs that embed it.
|
|
137
|
+
|
|
65
138
|
The Playwright version is pinned and must match the browser the sandbox base image carries
|
|
66
139
|
(`PLAYWRIGHT_VERSION` in `@zenera/sandbox`; a test keeps them equal).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenera/browser",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "An html page in a real browser, served as a zen chat serves it: checked for errors, driven, photographed.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"playwright",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"prepack": "tsc -b"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@zenera/engine": "^1.4.
|
|
45
|
-
"@zenera/sandbox": "^1.4.
|
|
44
|
+
"@zenera/engine": "^1.4.3",
|
|
45
|
+
"@zenera/sandbox": "^1.4.3",
|
|
46
46
|
"playwright-core": "1.65.1"
|
|
47
47
|
}
|
|
48
48
|
}
|