@zenera/browser 1.4.1 → 1.4.2

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.
Files changed (2) hide show
  1. package/README.md +112 -39
  2. 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 is what `zen page` (in [`@zenera/cli`](../cli)) runs on, and what agents' browser
25
- tools will run on.
26
-
27
- - **`PageHost`** answers a local page's requests with `@zenera/engine`'s `serveViewPath`, the code
28
- behind a chat's `/v/` pages: its files under the view CSP, its `*.api.py` functions run in a
29
- `ProcessSandbox`. No port: an in-process server on a private Unix socket.
30
- - **`PageSession`** is one tab: in a remote browser when `ZEN_BROWSER_URL` names one (a Playwright
31
- `run-server` at `ws://…`, or a DevTools endpoint at `http://…`), else in a local headless
32
- Chromium; a remote one that is full or down is tried twice more, then the local one is used. It routes the page's requests (its own files, three CDNs, nothing else), waits for
33
- the page to settle, collects what went wrong, and takes snapshots with refs and screenshots.
34
- - **`checkPage`** loads a page once and reports errors, failed function calls and sideways
35
- scrolling, with screenshots at the chat panel's width, a wide one and dark.
36
- - **`WIDTH_PRESETS`** are the widths a page is looked at: `panel` 400, `wide-panel` 640, `tab`
37
- 1280, one on each side of the kit's layout breakpoints. Screenshots are cut at `SHOT_HEIGHT`
38
- (1600 px), or split into parts, so a model can still read them.
39
- - **`resolveTarget`** turns a page folder, an html file or a URL into the pages and the files
40
- they are served from; **`installBrowser`** fetches the headless Chromium.
41
-
42
- ```ts
43
- import {
44
- checkPage,
45
- DEFAULT_WIDTHS,
46
- PageHost,
47
- PageSession,
48
- pythonPath,
49
- resolveTarget,
50
- } from '@zenera/browser';
51
-
52
- const target = resolveTarget('/workspace/pages/todo', process.cwd());
53
- const host = await PageHost.start({ trees: target.trees!, pythonPath: pythonPath() });
54
- const session = await PageSession.open(host);
55
- const report = await checkPage(session, target.pages[0]!, {
56
- widths: [...DEFAULT_WIDTHS],
57
- dark: true,
58
- outDir: target.outDir,
59
- timeoutMs: 15_000,
60
- });
61
- await session.close();
62
- await host.close();
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.1",
3
+ "version": "1.4.2",
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.1",
45
- "@zenera/sandbox": "^1.4.1",
44
+ "@zenera/engine": "^1.4.2",
45
+ "@zenera/sandbox": "^1.4.2",
46
46
  "playwright-core": "1.65.1"
47
47
  }
48
48
  }