@zenera/browser 0.0.0-stage → 1.3.39
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/LICENSE +21 -0
- package/README.md +65 -2
- package/dist/host.d.ts +39 -0
- package/dist/host.js +162 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +10 -0
- package/dist/install.d.ts +3 -0
- package/dist/install.js +23 -0
- package/dist/report.d.ts +39 -0
- package/dist/report.js +115 -0
- package/dist/session.d.ts +93 -0
- package/dist/session.js +412 -0
- package/dist/target.d.ts +22 -0
- package/dist/target.js +96 -0
- package/dist/widths.d.ts +18 -0
- package/dist/widths.js +51 -0
- package/package.json +47 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrey Ryabov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img
|
|
3
|
+
src="https://raw.githubusercontent.com/zenera-ai/ZeneraNeo/main/docs/imgs/zenera-logo-with-media-queries.svg"
|
|
4
|
+
alt="Zenera Logo"
|
|
5
|
+
width="20"
|
|
6
|
+
/>
|
|
7
|
+
<div>Powered By Zenera</div>
|
|
8
|
+
</div>
|
|
9
|
+
<br>
|
|
2
10
|
|
|
3
|
-
|
|
11
|
+
<div align="center">
|
|
12
|
+
<img src="https://raw.githubusercontent.com/zenera-ai/ZeneraNeo/main/docs/imgs/banner-browser-with-media-queries.svg" alt="ZENERA BROWSER" width="1008">
|
|
13
|
+
|
|
14
|
+
[](https://www.npmjs.com/package/@zenera/browser)
|
|
15
|
+
[](https://github.com/zenera-ai/ZeneraNeo/blob/main/LICENSE)
|
|
16
|
+
[](https://nodejs.org)
|
|
17
|
+
[](https://github.com/zenera-ai/ZeneraNeo/actions/workflows/ci.yml)
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
# @zenera/browser
|
|
22
|
+
|
|
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. 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();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The Playwright version is pinned and must match the browser the sandbox base image carries
|
|
66
|
+
(`PLAYWRIGHT_VERSION` in `@zenera/sandbox`; a test keeps them equal).
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AppCalls, type AppCallThread, type FileTrees } from '@zenera/engine';
|
|
2
|
+
/** Where a local page is opened from: a name that never resolves, answered by the host only. */
|
|
3
|
+
export declare const PAGE_ORIGIN = "https://page.invalid";
|
|
4
|
+
export interface PageRequest {
|
|
5
|
+
method: string;
|
|
6
|
+
/** the agent path with its query: `/workspace/pages/todo/api/items/list?x=1` */
|
|
7
|
+
path: string;
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
body?: Buffer;
|
|
10
|
+
}
|
|
11
|
+
export interface PageAnswer {
|
|
12
|
+
status: number;
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
body: Buffer;
|
|
15
|
+
}
|
|
16
|
+
export interface PageHostOptions {
|
|
17
|
+
trees: FileTrees;
|
|
18
|
+
/** directories in front of PYTHONPATH for a page's functions: zen's runtime library */
|
|
19
|
+
pythonPath?: readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* Where a page's functions run, and for whom: a host's AppCalls for the session's thread.
|
|
22
|
+
* Unset: in this process's environment (a ProcessSandbox), acting for nobody in particular.
|
|
23
|
+
*/
|
|
24
|
+
calls?: {
|
|
25
|
+
calls: AppCalls;
|
|
26
|
+
thread: AppCallThread;
|
|
27
|
+
user: Parameters<AppCalls['serve']>[4];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare class PageHost {
|
|
31
|
+
#private;
|
|
32
|
+
readonly trees: FileTrees;
|
|
33
|
+
private constructor();
|
|
34
|
+
static start(opts: PageHostOptions): Promise<PageHost>;
|
|
35
|
+
/** One request, as the browser made it, answered as `/v/` would answer it. */
|
|
36
|
+
fetch(req: PageRequest): Promise<PageAnswer>;
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=host.d.ts.map
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { createServer, request, } from 'node:http';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { AppCalls, serveViewPath, ViewError, } from '@zenera/engine';
|
|
6
|
+
import { ProcessSandbox } from '@zenera/sandbox';
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Serving a page to `zen page`'s browser the way `/v/` serves it
|
|
9
|
+
//
|
|
10
|
+
// The browser asks for `https://page.invalid/<agent path>`; `zen page` hands every such request
|
|
11
|
+
// here, to the very `serveViewPath` zen server's `/v/` route and zenera-project's Test-tab views
|
|
12
|
+
// call: what a path is (a file, a function of an `*.api.py`, or nothing), the view CSP, the
|
|
13
|
+
// call limits. Nothing here knows how a page's functions run. By default they run in a
|
|
14
|
+
// ProcessSandbox, for `zen page`, which is already where the session's commands run (inside its
|
|
15
|
+
// sandbox) or on a person's own machine for their own folder. A host outside the sandbox (zen
|
|
16
|
+
// server's browser tools) passes its own `calls`: the session's AppCalls, which run them there.
|
|
17
|
+
//
|
|
18
|
+
// `serveViewPath` speaks Node's http, so it is served on a Unix socket in a private temp
|
|
19
|
+
// folder (no port: a pod's loopback is shared by its users) and asked over it.
|
|
20
|
+
//
|
|
21
|
+
// Main: PageHost.start(trees) - the server; host.fetch(...) - one request through it;
|
|
22
|
+
// PAGE_ORIGIN - the origin pages are opened under.
|
|
23
|
+
// Used by: session.ts (the browser's request handler); @zenera/cli `zen page`.
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
/** Where a local page is opened from: a name that never resolves, answered by the host only. */
|
|
26
|
+
export const PAGE_ORIGIN = 'https://page.invalid';
|
|
27
|
+
/**
|
|
28
|
+
* Request headers not passed on: the host answers uncompressed and whole (a routed browser keeps
|
|
29
|
+
* no cache to revalidate), and is no one's host.
|
|
30
|
+
*/
|
|
31
|
+
const DROPPED = new Set([
|
|
32
|
+
'host',
|
|
33
|
+
'accept-encoding',
|
|
34
|
+
'connection',
|
|
35
|
+
'content-length',
|
|
36
|
+
'if-none-match',
|
|
37
|
+
'if-modified-since',
|
|
38
|
+
'if-range',
|
|
39
|
+
]);
|
|
40
|
+
/** Response headers about the connection to the host, not about the answer. */
|
|
41
|
+
const HOP = new Set(['connection', 'keep-alive', 'transfer-encoding', 'date']);
|
|
42
|
+
export class PageHost {
|
|
43
|
+
trees;
|
|
44
|
+
#server;
|
|
45
|
+
#dir;
|
|
46
|
+
#socket;
|
|
47
|
+
#calls;
|
|
48
|
+
/** ours to close: the default, not a host's */
|
|
49
|
+
#ownCalls;
|
|
50
|
+
constructor(opts, server, dir, socket) {
|
|
51
|
+
this.trees = opts.trees;
|
|
52
|
+
this.#server = server;
|
|
53
|
+
this.#dir = dir;
|
|
54
|
+
this.#socket = socket;
|
|
55
|
+
// A fresh one each time: AppCalls closes a kept sandbox after a while without calls.
|
|
56
|
+
const sandbox = () => new ProcessSandbox({
|
|
57
|
+
root: opts.trees.workspace,
|
|
58
|
+
...(opts.pythonPath?.length
|
|
59
|
+
? {
|
|
60
|
+
execPaths: { PYTHONPATH: opts.pythonPath },
|
|
61
|
+
// zen's own runtime sources: no __pycache__ written beside them.
|
|
62
|
+
env: { ...process.env, PYTHONDONTWRITEBYTECODE: '1' },
|
|
63
|
+
}
|
|
64
|
+
: {}),
|
|
65
|
+
});
|
|
66
|
+
this.#ownCalls = opts.calls
|
|
67
|
+
? null
|
|
68
|
+
: new AppCalls({ open: async () => ({ sandbox: sandbox() }) });
|
|
69
|
+
this.#calls = opts.calls ?? {
|
|
70
|
+
calls: this.#ownCalls,
|
|
71
|
+
// One page session, one owner; the sandbox is ours, so no session to open.
|
|
72
|
+
thread: { owner: 'zen-page', id: 'page', session: undefined },
|
|
73
|
+
user: null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
static async start(opts) {
|
|
77
|
+
// mkdtemp makes the folder 0700: nobody else on the machine reaches the socket.
|
|
78
|
+
const dir = mkdtempSync(join(tmpdir(), 'zen-page-'));
|
|
79
|
+
const socket = join(dir, 'view.sock');
|
|
80
|
+
const holder = {};
|
|
81
|
+
const server = createServer((req, res) => void holder.host.#serve(req, res));
|
|
82
|
+
const host = new PageHost(opts, server, dir, socket);
|
|
83
|
+
holder.host = host;
|
|
84
|
+
await new Promise((settle, fail) => {
|
|
85
|
+
server.once('error', fail);
|
|
86
|
+
server.listen(socket, () => {
|
|
87
|
+
server.off('error', fail);
|
|
88
|
+
settle();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return host;
|
|
92
|
+
}
|
|
93
|
+
async #serve(req, res) {
|
|
94
|
+
let path;
|
|
95
|
+
try {
|
|
96
|
+
path = decodeURIComponent(new URL(req.url ?? '/', PAGE_ORIGIN).pathname);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
res.statusCode = 400;
|
|
100
|
+
res.end('bad path');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
await serveViewPath(req, res, {
|
|
105
|
+
path,
|
|
106
|
+
trees: this.trees,
|
|
107
|
+
calls: this.#calls,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (!(err instanceof ViewError)) {
|
|
112
|
+
console.warn(`zen page: serving ${path} failed:`, err);
|
|
113
|
+
}
|
|
114
|
+
if (res.headersSent) {
|
|
115
|
+
res.destroy();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
res.statusCode = err instanceof ViewError ? err.status : 500;
|
|
119
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
120
|
+
res.end(err instanceof Error ? err.message : String(err));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** One request, as the browser made it, answered as `/v/` would answer it. */
|
|
124
|
+
fetch(req) {
|
|
125
|
+
const headers = {};
|
|
126
|
+
for (const [k, v] of Object.entries(req.headers)) {
|
|
127
|
+
if (!DROPPED.has(k.toLowerCase()))
|
|
128
|
+
headers[k] = v;
|
|
129
|
+
}
|
|
130
|
+
if (req.body?.length)
|
|
131
|
+
headers['content-length'] = String(req.body.length);
|
|
132
|
+
return new Promise((settle, fail) => {
|
|
133
|
+
const out = request({ socketPath: this.#socket, method: req.method, path: req.path, headers }, (res) => {
|
|
134
|
+
const chunks = [];
|
|
135
|
+
res.on('data', (c) => chunks.push(c));
|
|
136
|
+
res.on('end', () => settle({
|
|
137
|
+
status: res.statusCode ?? 500,
|
|
138
|
+
headers: flat(res.headers),
|
|
139
|
+
body: Buffer.concat(chunks),
|
|
140
|
+
}));
|
|
141
|
+
res.on('error', fail);
|
|
142
|
+
});
|
|
143
|
+
out.on('error', fail);
|
|
144
|
+
out.end(req.body);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async close() {
|
|
148
|
+
await this.#ownCalls?.close();
|
|
149
|
+
await new Promise((settle) => this.#server.close(() => settle()));
|
|
150
|
+
rmSync(this.#dir, { recursive: true, force: true });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function flat(headers) {
|
|
154
|
+
const out = {};
|
|
155
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
156
|
+
if (v === undefined || HOP.has(k))
|
|
157
|
+
continue;
|
|
158
|
+
out[k] = Array.isArray(v) ? v.join(', ') : v;
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=host.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The public API of @zenera/browser: an html page in a real browser, served as the chat serves
|
|
2
|
+
// it, for `zen page` (the html-page skill's check) and, later, agents' browser tools.
|
|
3
|
+
// Import from '@zenera/browser', not a file.
|
|
4
|
+
export * from "./host.js";
|
|
5
|
+
export * from "./install.js";
|
|
6
|
+
export * from "./report.js";
|
|
7
|
+
export * from "./session.js";
|
|
8
|
+
export * from "./target.js";
|
|
9
|
+
export * from "./widths.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Fetching the browser this package drives
|
|
6
|
+
//
|
|
7
|
+
// Chromium's headless shell for the Playwright this package depends on, through Playwright's own
|
|
8
|
+
// installer, into its default place (or PLAYWRIGHT_BROWSERS_PATH). The sandbox base image does
|
|
9
|
+
// the same at build time; this is for a person's machine.
|
|
10
|
+
//
|
|
11
|
+
// Main: installBrowser.
|
|
12
|
+
// Used by: @zenera/cli `zen page install`.
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/** Installs the headless shell (and, as root on Linux, the libraries it needs); its exit code. */
|
|
15
|
+
export function installBrowser() {
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
const cli = join(dirname(require.resolve('playwright-core/package.json')), 'cli.js');
|
|
18
|
+
const args = [cli, 'install', '--only-shell', 'chromium'];
|
|
19
|
+
if (process.platform === 'linux' && process.getuid?.() === 0)
|
|
20
|
+
args.splice(2, 0, '--with-deps');
|
|
21
|
+
return spawnSync(process.execPath, args, { stdio: 'inherit' }).status ?? 1;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=install.js.map
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PageSession, Problem } from './session.ts';
|
|
2
|
+
export interface CheckOptions {
|
|
3
|
+
/** widths, the first the panel's (sideways scrolling there is an error) */
|
|
4
|
+
widths: number[];
|
|
5
|
+
dark: boolean;
|
|
6
|
+
outDir: string;
|
|
7
|
+
/** ms to wait for the page to settle */
|
|
8
|
+
timeoutMs: number;
|
|
9
|
+
/** write the card's preview beside a local page (previewFile); not for a URL */
|
|
10
|
+
preview?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PageScreenshot {
|
|
13
|
+
file: string;
|
|
14
|
+
width: number;
|
|
15
|
+
dark: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface PageReport {
|
|
18
|
+
page: string;
|
|
19
|
+
ms: number;
|
|
20
|
+
pending: string[];
|
|
21
|
+
problems: Problem[];
|
|
22
|
+
screenshots: PageScreenshot[];
|
|
23
|
+
/** the page's height at the panel's width, px: taller than SHOT_HEIGHT, the shots are its top */
|
|
24
|
+
height: number;
|
|
25
|
+
/** the card's preview written beside the page */
|
|
26
|
+
preview?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Where a page's card picture goes: beside it, preview.png for index.html, report.preview.png
|
|
30
|
+
* for report.html - the og:image the html-page build names. Null for a URL.
|
|
31
|
+
*/
|
|
32
|
+
export declare function previewFile(page: string): string | null;
|
|
33
|
+
export declare function checkPage(session: PageSession, page: string, opts: CheckOptions,
|
|
34
|
+
/** the page is open already (a running session): check it as it is */
|
|
35
|
+
loaded?: boolean): Promise<PageReport>;
|
|
36
|
+
export declare const errorsIn: (r: PageReport) => number;
|
|
37
|
+
/** The report as the agent reads it: a line per problem, then the screenshots. */
|
|
38
|
+
export declare function reportLines(r: PageReport, shown: (path: string) => string): string[];
|
|
39
|
+
//# sourceMappingURL=report.d.ts.map
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { accessSync, constants } from 'node:fs';
|
|
2
|
+
import { basename, dirname, extname, join } from 'node:path';
|
|
3
|
+
import { PREVIEW, SHOT_HEIGHT, short } from "./session.js";
|
|
4
|
+
import { widthName } from "./widths.js";
|
|
5
|
+
/**
|
|
6
|
+
* Where a page's card picture goes: beside it, preview.png for index.html, report.preview.png
|
|
7
|
+
* for report.html - the og:image the html-page build names. Null for a URL.
|
|
8
|
+
*/
|
|
9
|
+
export function previewFile(page) {
|
|
10
|
+
if (/^https?:\/\//i.test(page))
|
|
11
|
+
return null;
|
|
12
|
+
const base = basename(page).replace(/\.html?$/i, '');
|
|
13
|
+
return join(dirname(page), base === 'index' ? 'preview.png' : `${base}.preview.png`);
|
|
14
|
+
}
|
|
15
|
+
export async function checkPage(session, page, opts,
|
|
16
|
+
/** the page is open already (a running session): check it as it is */
|
|
17
|
+
loaded = false) {
|
|
18
|
+
const problems = [];
|
|
19
|
+
const screenshots = [];
|
|
20
|
+
let height = 0;
|
|
21
|
+
const [panel, ...wider] = opts.widths;
|
|
22
|
+
await session.setView({ width: panel, dark: false });
|
|
23
|
+
const settled = loaded
|
|
24
|
+
? await session.settle(opts.timeoutMs)
|
|
25
|
+
: await session.goto(page, opts.timeoutMs);
|
|
26
|
+
if (settled.pending.length) {
|
|
27
|
+
problems.push({
|
|
28
|
+
level: 'warning',
|
|
29
|
+
text: `still loading after ${(opts.timeoutMs / 1000).toFixed(0)} s - waiting on ${settled.pending.join(', ')}`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (await session.empty()) {
|
|
33
|
+
problems.push({ level: 'error', text: 'the page shows nothing: no text, no picture' });
|
|
34
|
+
}
|
|
35
|
+
const base = basename(short(page), extname(short(page))) || 'page';
|
|
36
|
+
const shot = async (width, dark) => {
|
|
37
|
+
const file = join(opts.outDir, `${base}-${widthName(width)}${dark ? '-dark' : ''}.png`);
|
|
38
|
+
const taken = await session.screenshot(file, { width, dark });
|
|
39
|
+
if (width === panel && !dark)
|
|
40
|
+
height = taken.height;
|
|
41
|
+
screenshots.push({ file, width, dark });
|
|
42
|
+
};
|
|
43
|
+
const sideways = async (width) => {
|
|
44
|
+
const o = await session.overflow();
|
|
45
|
+
if (!o)
|
|
46
|
+
return;
|
|
47
|
+
problems.push({
|
|
48
|
+
level: width === panel ? 'error' : 'warning',
|
|
49
|
+
text: `${widthName(width)} (${width} px): the page is ${o.width} px wide and scrolls sideways${o.elements.length ? ` - ${o.elements.join('; ')}` : ''}`,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
await sideways(panel);
|
|
53
|
+
await shot(panel, false);
|
|
54
|
+
for (const width of wider) {
|
|
55
|
+
await session.setView({ width });
|
|
56
|
+
await session.settle(2000);
|
|
57
|
+
await sideways(width);
|
|
58
|
+
await shot(width, false);
|
|
59
|
+
}
|
|
60
|
+
if (opts.dark)
|
|
61
|
+
await shot(panel, true);
|
|
62
|
+
let preview;
|
|
63
|
+
const card = opts.preview ? previewFile(page) : null;
|
|
64
|
+
if (card) {
|
|
65
|
+
try {
|
|
66
|
+
accessSync(dirname(card), constants.W_OK);
|
|
67
|
+
await session.preview(card);
|
|
68
|
+
preview = card;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
problems.push({
|
|
72
|
+
level: 'warning',
|
|
73
|
+
text: `could not write ${card}: the chat's card for the page shows no picture`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
await session.setView({ width: panel, dark: false });
|
|
78
|
+
problems.unshift(...session.takeProblems());
|
|
79
|
+
return {
|
|
80
|
+
page,
|
|
81
|
+
ms: settled.ms,
|
|
82
|
+
pending: settled.pending,
|
|
83
|
+
problems,
|
|
84
|
+
screenshots,
|
|
85
|
+
height,
|
|
86
|
+
preview,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export const errorsIn = (r) => r.problems.filter((p) => p.level === 'error').length;
|
|
90
|
+
/** The report as the agent reads it: a line per problem, then the screenshots. */
|
|
91
|
+
export function reportLines(r, shown) {
|
|
92
|
+
const lines = [];
|
|
93
|
+
const name = short(r.page);
|
|
94
|
+
lines.push(errorsIn(r)
|
|
95
|
+
? `✗ ${name}: ${errorsIn(r)} error${errorsIn(r) > 1 ? 's' : ''} (loaded in ${(r.ms / 1000).toFixed(1)} s)`
|
|
96
|
+
: `✓ ${name} loaded in ${(r.ms / 1000).toFixed(1)} s`);
|
|
97
|
+
for (const p of r.problems)
|
|
98
|
+
lines.push(`${p.level === 'error' ? '✗' : '⚠'} ${p.text}`);
|
|
99
|
+
if (r.screenshots.length) {
|
|
100
|
+
lines.push('screenshots - open them all at once, one view_image each in the same reply:');
|
|
101
|
+
for (const s of r.screenshots) {
|
|
102
|
+
const at = `${widthName(s.width)}, ${s.width} px${s.dark ? ', dark' : ''}`;
|
|
103
|
+
lines.push(` ${shown(s.file)} (${at})`);
|
|
104
|
+
}
|
|
105
|
+
if (r.preview) {
|
|
106
|
+
lines.push(` ${shown(r.preview)} (the chat's card for the page, ${PREVIEW.width}×${PREVIEW.height}, light)`);
|
|
107
|
+
}
|
|
108
|
+
if (r.height > SHOT_HEIGHT) {
|
|
109
|
+
lines.push(` the page is ${r.height} px tall: these show its top ${SHOT_HEIGHT} px; ` +
|
|
110
|
+
'`zen page screenshot --full` (in a session) takes the rest in parts');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return lines;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Browser, BrowserContext, Locator, Page } from 'playwright-core';
|
|
2
|
+
import { type PageHost } from './host.ts';
|
|
3
|
+
export type Level = 'error' | 'warning';
|
|
4
|
+
export interface Problem {
|
|
5
|
+
level: Level;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Settled {
|
|
9
|
+
ms: number;
|
|
10
|
+
/** requests still going when the wait gave up: what the page waits on */
|
|
11
|
+
pending: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface Overflow {
|
|
14
|
+
width: number;
|
|
15
|
+
viewport: number;
|
|
16
|
+
elements: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface ShotOptions {
|
|
19
|
+
width?: number;
|
|
20
|
+
dark?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* `top` (default): the page from its top, at most SHOT_HEIGHT tall; `full`: all of it, in
|
|
23
|
+
* parts of SHOT_HEIGHT (`<name>-1.png`, `-2.png`, ...); `viewport`: what a window shows
|
|
24
|
+
*/
|
|
25
|
+
area?: 'top' | 'full' | 'viewport';
|
|
26
|
+
/** one element only: a ref or a selector */
|
|
27
|
+
target?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Shot {
|
|
30
|
+
/** the files written, top to bottom */
|
|
31
|
+
files: string[];
|
|
32
|
+
/** the page's whole height, px */
|
|
33
|
+
height: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The tallest image a screenshot is: a model looking at it shrinks anything with a longer edge
|
|
37
|
+
* than ~1568 px, and a 400 px wide page 4000 px tall would arrive too small to read.
|
|
38
|
+
*/
|
|
39
|
+
export declare const SHOT_HEIGHT = 1600;
|
|
40
|
+
/** The picture of a page the chat's card shows (og:image): a wide first screen, light, 1.91:1. */
|
|
41
|
+
export declare const PREVIEW: {
|
|
42
|
+
readonly width: 1200;
|
|
43
|
+
readonly height: 630;
|
|
44
|
+
};
|
|
45
|
+
export declare class BrowserMissing extends Error {
|
|
46
|
+
}
|
|
47
|
+
/** The browser ZEN_BROWSER_URL names, else a local headless Chromium. */
|
|
48
|
+
export declare function openBrowser(): Promise<Browser>;
|
|
49
|
+
export declare class PageSession {
|
|
50
|
+
#private;
|
|
51
|
+
readonly browser: Browser;
|
|
52
|
+
readonly context: BrowserContext;
|
|
53
|
+
readonly page: Page;
|
|
54
|
+
private constructor();
|
|
55
|
+
/** A tab at the panel's width, answering local pages through `host` when given. */
|
|
56
|
+
static open(host: PageHost | null, browser?: Browser): Promise<PageSession>;
|
|
57
|
+
/** What went wrong since the last call, each once (with how often it happened). */
|
|
58
|
+
takeProblems(): Problem[];
|
|
59
|
+
/** The URL a target opens at: a local agent path under PAGE_ORIGIN, or a URL as it is. */
|
|
60
|
+
urlOf(target: string): string;
|
|
61
|
+
goto(target: string, capMs?: number): Promise<Settled>;
|
|
62
|
+
reload(capMs?: number): Promise<Settled>;
|
|
63
|
+
/**
|
|
64
|
+
* Waits until nothing has been in flight for QUIET_MS (page functions included: they are
|
|
65
|
+
* requests), nothing says `aria-busy="true"`, fonts are in and two frames are drawn.
|
|
66
|
+
*/
|
|
67
|
+
settle(capMs?: number): Promise<Settled>;
|
|
68
|
+
/** The page as text, each element with a ref (`[ref=e5]`) the actions take. */
|
|
69
|
+
snapshot(maxLines?: number): Promise<string>;
|
|
70
|
+
/** A ref from the last snapshot (`e5`, `@e5`), or a Playwright selector. */
|
|
71
|
+
locate(target: string): Locator;
|
|
72
|
+
setView(opts: {
|
|
73
|
+
width?: number;
|
|
74
|
+
dark?: boolean;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
/** The page at its current width and scheme (or those asked for), into `file` (or parts of it). */
|
|
77
|
+
screenshot(file: string, opts?: ShotOptions): Promise<Shot>;
|
|
78
|
+
/**
|
|
79
|
+
* The page's first screen at PREVIEW's size, light, into `file`: the picture its card shows.
|
|
80
|
+
* The window is put back as it was.
|
|
81
|
+
*/
|
|
82
|
+
preview(file: string): Promise<void>;
|
|
83
|
+
/** Whether the page scrolls sideways at its width, and the elements furthest out. */
|
|
84
|
+
overflow(): Promise<Overflow | null>;
|
|
85
|
+
/** A page that drew nothing: no text and no picture. */
|
|
86
|
+
empty(): Promise<boolean>;
|
|
87
|
+
close(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
/** An error as one line: Playwright's carry a call log after the first lines. */
|
|
90
|
+
export declare function errorText(err: unknown): string;
|
|
91
|
+
/** A URL as worth reading: a local page's agent path, else the URL without its query. */
|
|
92
|
+
export declare function short(url: string): string;
|
|
93
|
+
//# sourceMappingURL=session.d.ts.map
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { VIEW_CDNS } from '@zenera/engine';
|
|
4
|
+
import { PAGE_ORIGIN } from "./host.js";
|
|
5
|
+
import { WIDTH_PRESETS } from "./widths.js";
|
|
6
|
+
/**
|
|
7
|
+
* The tallest image a screenshot is: a model looking at it shrinks anything with a longer edge
|
|
8
|
+
* than ~1568 px, and a 400 px wide page 4000 px tall would arrive too small to read.
|
|
9
|
+
*/
|
|
10
|
+
export const SHOT_HEIGHT = 1600;
|
|
11
|
+
/** The picture of a page the chat's card shows (og:image): a wide first screen, light, 1.91:1. */
|
|
12
|
+
export const PREVIEW = { width: 1200, height: 630 };
|
|
13
|
+
/** A `full` screenshot stops after this many parts. */
|
|
14
|
+
const MAX_PARTS = 8;
|
|
15
|
+
const PANEL = { width: WIDTH_PRESETS.panel, height: 900 };
|
|
16
|
+
const QUIET_MS = 500;
|
|
17
|
+
const CDN_HOSTS = new Set(VIEW_CDNS.map((u) => new URL(u).host));
|
|
18
|
+
export class BrowserMissing extends Error {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What runs in the page, as source: this package is typed for Node, not the DOM, and these
|
|
22
|
+
* never run here.
|
|
23
|
+
*/
|
|
24
|
+
const IN_PAGE = {
|
|
25
|
+
drawn: `new Promise((done) => document.fonts.ready.then(() =>
|
|
26
|
+
requestAnimationFrame(() => requestAnimationFrame(() => done()))))`,
|
|
27
|
+
busy: `document.querySelector('[aria-busy="true"]') !== null`,
|
|
28
|
+
height: `document.documentElement.scrollHeight`,
|
|
29
|
+
empty: `!document.body || (document.body.innerText.trim() === '' &&
|
|
30
|
+
!document.querySelector('img, canvas, svg, video'))`,
|
|
31
|
+
// Whether the page scrolls sideways, and the outermost elements that stick out furthest
|
|
32
|
+
// (an element whose parent sticks out as far is not the cause).
|
|
33
|
+
overflow: `(() => {
|
|
34
|
+
const root = document.documentElement;
|
|
35
|
+
const viewport = root.clientWidth;
|
|
36
|
+
if (root.scrollWidth <= viewport + 1) return null;
|
|
37
|
+
const name = (e) => {
|
|
38
|
+
const id = e.id ? '#' + e.id : '';
|
|
39
|
+
const cls = [...e.classList].slice(0, 2).map((c) => '.' + c).join('');
|
|
40
|
+
const text = (e.textContent || '').trim().replace(/\\s+/g, ' ').slice(0, 30);
|
|
41
|
+
return e.tagName.toLowerCase() + id + cls + (text ? ' "' + text + '"' : '');
|
|
42
|
+
};
|
|
43
|
+
const elements = [...document.body.querySelectorAll('*')]
|
|
44
|
+
.map((e) => ({ e, r: e.getBoundingClientRect() }))
|
|
45
|
+
.filter((x) => x.r.width > 0 && x.r.right > viewport + 1)
|
|
46
|
+
.filter((x) => {
|
|
47
|
+
const p = x.e.parentElement && x.e.parentElement.getBoundingClientRect();
|
|
48
|
+
return !p || p.right < x.r.right - 1;
|
|
49
|
+
})
|
|
50
|
+
.sort((a, b) => b.r.right - a.r.right)
|
|
51
|
+
.slice(0, 3)
|
|
52
|
+
.map((x) => name(x.e) + ' (to ' + Math.round(x.r.right) + ' px)');
|
|
53
|
+
return { width: root.scrollWidth, viewport, elements };
|
|
54
|
+
})()`,
|
|
55
|
+
};
|
|
56
|
+
/** The browser ZEN_BROWSER_URL names, else a local headless Chromium. */
|
|
57
|
+
export async function openBrowser() {
|
|
58
|
+
const { chromium } = await import('playwright-core');
|
|
59
|
+
const remote = process.env.ZEN_BROWSER_URL;
|
|
60
|
+
if (remote) {
|
|
61
|
+
return /^wss?:/i.test(remote) ? chromium.connect(remote) : chromium.connectOverCDP(remote);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return await chromium.launch({
|
|
65
|
+
headless: true,
|
|
66
|
+
args: process.platform === 'linux' ? ['--disable-dev-shm-usage', '--disable-gpu'] : [],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (/Executable doesn't exist|install/i.test(String(err.message))) {
|
|
71
|
+
throw new BrowserMissing('no browser installed for zen page');
|
|
72
|
+
}
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const isRef = (s) => /^@?(f\d+)?e\d+$/.test(s);
|
|
77
|
+
/** A private or loopback name or address, as far as it can be told without resolving it. */
|
|
78
|
+
function privateHost(host) {
|
|
79
|
+
const h = host.replace(/^\[|\]$/g, '').toLowerCase();
|
|
80
|
+
if (h === 'localhost' || h.endsWith('.localhost') || h.endsWith('.internal'))
|
|
81
|
+
return true;
|
|
82
|
+
if (h === '::1' || h.startsWith('fc') || h.startsWith('fd') || h.startsWith('fe80')) {
|
|
83
|
+
return h.includes(':');
|
|
84
|
+
}
|
|
85
|
+
const m = /^(\d+)\.(\d+)\.\d+\.\d+$/.exec(h);
|
|
86
|
+
if (!m)
|
|
87
|
+
return false;
|
|
88
|
+
const [a, b] = [Number(m[1]), Number(m[2])];
|
|
89
|
+
return (a === 0 ||
|
|
90
|
+
a === 10 ||
|
|
91
|
+
a === 127 ||
|
|
92
|
+
(a === 169 && b === 254) ||
|
|
93
|
+
(a === 172 && b >= 16 && b <= 31) ||
|
|
94
|
+
(a === 192 && b === 168) ||
|
|
95
|
+
(a === 100 && b >= 64 && b <= 127));
|
|
96
|
+
}
|
|
97
|
+
export class PageSession {
|
|
98
|
+
browser;
|
|
99
|
+
context;
|
|
100
|
+
page;
|
|
101
|
+
#host;
|
|
102
|
+
#owned;
|
|
103
|
+
#inflight = new Map();
|
|
104
|
+
#problems = [];
|
|
105
|
+
#seen = new Map();
|
|
106
|
+
constructor(browser, context, page, host, owned) {
|
|
107
|
+
this.browser = browser;
|
|
108
|
+
this.context = context;
|
|
109
|
+
this.page = page;
|
|
110
|
+
this.#host = host;
|
|
111
|
+
this.#owned = owned;
|
|
112
|
+
}
|
|
113
|
+
/** A tab at the panel's width, answering local pages through `host` when given. */
|
|
114
|
+
static async open(host, browser) {
|
|
115
|
+
const b = browser ?? (await openBrowser());
|
|
116
|
+
const context = await b.newContext({
|
|
117
|
+
viewport: PANEL,
|
|
118
|
+
colorScheme: 'light',
|
|
119
|
+
deviceScaleFactor: 1,
|
|
120
|
+
serviceWorkers: 'block',
|
|
121
|
+
});
|
|
122
|
+
const page = await context.newPage();
|
|
123
|
+
const session = new PageSession(b, context, page, host, browser === undefined);
|
|
124
|
+
await session.#wire();
|
|
125
|
+
return session;
|
|
126
|
+
}
|
|
127
|
+
async #wire() {
|
|
128
|
+
await this.context.route('**/*', (route) => this.#route(route));
|
|
129
|
+
const p = this.page;
|
|
130
|
+
p.on('request', (r) => this.#inflight.set(r, Date.now()));
|
|
131
|
+
p.on('requestfinished', (r) => this.#inflight.delete(r));
|
|
132
|
+
p.on('requestfailed', (r) => {
|
|
133
|
+
this.#inflight.delete(r);
|
|
134
|
+
const why = r.failure()?.errorText ?? 'failed';
|
|
135
|
+
// Refused by our own route or by the CSP: reported there, with the reason.
|
|
136
|
+
if (why.includes('ERR_BLOCKED_BY_CLIENT') || why === 'csp')
|
|
137
|
+
return;
|
|
138
|
+
this.#add('error', `request failed: ${r.method()} ${short(r.url())} (${why})`);
|
|
139
|
+
});
|
|
140
|
+
p.on('pageerror', (err) => this.#add('error', `uncaught: ${err.message}`));
|
|
141
|
+
p.on('console', (m) => {
|
|
142
|
+
const t = m.type();
|
|
143
|
+
if (t !== 'error' && t !== 'warning')
|
|
144
|
+
return;
|
|
145
|
+
// Chrome's line for a failed request: the request itself is reported, better.
|
|
146
|
+
if (m.text().startsWith('Failed to load resource'))
|
|
147
|
+
return;
|
|
148
|
+
const where = m.location();
|
|
149
|
+
const at = where.url ? ` (${short(where.url)}:${where.lineNumber + 1})` : '';
|
|
150
|
+
const level = t === 'error' ? 'error' : 'warning';
|
|
151
|
+
this.#add(level, `console ${t}: ${m.text().slice(0, 500)}${at}`);
|
|
152
|
+
});
|
|
153
|
+
p.on('response', (res) => {
|
|
154
|
+
const req = res.request();
|
|
155
|
+
// A local answer is whole when it arrives (the host sent it in one piece); a page
|
|
156
|
+
// that never reads a body would otherwise keep it in flight.
|
|
157
|
+
if (req.url().startsWith(PAGE_ORIGIN))
|
|
158
|
+
this.#inflight.delete(req);
|
|
159
|
+
// A function's failure is reported by #route, with its message.
|
|
160
|
+
if (res.status() < 400 || res.headers()['x-zenera-call'])
|
|
161
|
+
return;
|
|
162
|
+
this.#add('error', `${req.method()} ${short(req.url())} → ${res.status()}`);
|
|
163
|
+
});
|
|
164
|
+
p.on('dialog', (d) => {
|
|
165
|
+
this.#add('error', `${d.type()} dialog opened: ${d.message().slice(0, 200)}`);
|
|
166
|
+
void d.dismiss().catch((err) => {
|
|
167
|
+
console.warn('zen page: dismissing a dialog failed; left open', err);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async #route(route) {
|
|
172
|
+
const req = route.request();
|
|
173
|
+
const url = new URL(req.url());
|
|
174
|
+
if (url.origin === PAGE_ORIGIN && this.#host) {
|
|
175
|
+
const answer = await this.#host.fetch({
|
|
176
|
+
method: req.method(),
|
|
177
|
+
path: url.pathname + url.search,
|
|
178
|
+
headers: await req.allHeaders(),
|
|
179
|
+
...(req.postDataBuffer() ? { body: req.postDataBuffer() } : {}),
|
|
180
|
+
});
|
|
181
|
+
if (answer.status >= 400 && answer.headers['x-zenera-call']) {
|
|
182
|
+
this.#add('error', `function ${req.method()} ${short(req.url())} → ${answer.status}${callDetail(answer.body)}`);
|
|
183
|
+
}
|
|
184
|
+
await route.fulfill({
|
|
185
|
+
status: answer.status,
|
|
186
|
+
headers: answer.headers,
|
|
187
|
+
body: answer.body,
|
|
188
|
+
});
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const local = this.#host !== null;
|
|
192
|
+
if (local ? CDN_HOSTS.has(url.host) : !privateHost(url.hostname)) {
|
|
193
|
+
await route.continue();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.#add('error', local
|
|
197
|
+
? `blocked: ${url.host} - a page may load only its own files and ${[...CDN_HOSTS].join(', ')}`
|
|
198
|
+
: `blocked: ${url.host} is a private address`);
|
|
199
|
+
await route.abort('blockedbyclient');
|
|
200
|
+
}
|
|
201
|
+
#add(level, text) {
|
|
202
|
+
const n = (this.#seen.get(text) ?? 0) + 1;
|
|
203
|
+
this.#seen.set(text, n);
|
|
204
|
+
if (n === 1)
|
|
205
|
+
this.#problems.push({ level, text });
|
|
206
|
+
}
|
|
207
|
+
/** What went wrong since the last call, each once (with how often it happened). */
|
|
208
|
+
takeProblems() {
|
|
209
|
+
const out = this.#problems.map((p) => {
|
|
210
|
+
const n = this.#seen.get(p.text) ?? 1;
|
|
211
|
+
return n > 1 ? { ...p, text: `${p.text} (×${n})` } : p;
|
|
212
|
+
});
|
|
213
|
+
this.#problems = [];
|
|
214
|
+
this.#seen = new Map();
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
/** The URL a target opens at: a local agent path under PAGE_ORIGIN, or a URL as it is. */
|
|
218
|
+
urlOf(target) {
|
|
219
|
+
if (/^https?:\/\//i.test(target))
|
|
220
|
+
return target;
|
|
221
|
+
if (!this.#host)
|
|
222
|
+
throw new Error(`not a URL: ${target}`);
|
|
223
|
+
return PAGE_ORIGIN + target.split('/').map(encodeURIComponent).join('/');
|
|
224
|
+
}
|
|
225
|
+
async goto(target, capMs = 15_000) {
|
|
226
|
+
const started = Date.now();
|
|
227
|
+
const url = this.urlOf(target);
|
|
228
|
+
try {
|
|
229
|
+
await this.page.goto(url, { waitUntil: 'load', timeout: capMs });
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
if (!/ERR_BLOCKED_BY_CLIENT/.test(String(err)))
|
|
233
|
+
throw err;
|
|
234
|
+
const why = this.takeProblems().map((p) => p.text);
|
|
235
|
+
throw new Error(why.length ? why.join('; ') : `blocked: ${short(url)}`);
|
|
236
|
+
}
|
|
237
|
+
const settled = await this.settle(Math.max(1000, capMs - (Date.now() - started)));
|
|
238
|
+
return { ...settled, ms: Date.now() - started };
|
|
239
|
+
}
|
|
240
|
+
async reload(capMs = 15_000) {
|
|
241
|
+
const started = Date.now();
|
|
242
|
+
await this.page.reload({ waitUntil: 'load', timeout: capMs });
|
|
243
|
+
const settled = await this.settle(capMs);
|
|
244
|
+
return { ...settled, ms: Date.now() - started };
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Waits until nothing has been in flight for QUIET_MS (page functions included: they are
|
|
248
|
+
* requests), nothing says `aria-busy="true"`, fonts are in and two frames are drawn.
|
|
249
|
+
*/
|
|
250
|
+
async settle(capMs = 5000) {
|
|
251
|
+
const started = Date.now();
|
|
252
|
+
const deadline = started + capMs;
|
|
253
|
+
let quietSince = 0;
|
|
254
|
+
while (Date.now() < deadline) {
|
|
255
|
+
if (this.#inflight.size === 0) {
|
|
256
|
+
quietSince ||= Date.now();
|
|
257
|
+
if (Date.now() - quietSince >= QUIET_MS && !(await this.#busy()))
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
quietSince = 0;
|
|
262
|
+
}
|
|
263
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
264
|
+
}
|
|
265
|
+
await this.page.evaluate(IN_PAGE.drawn).catch((err) => {
|
|
266
|
+
// A page navigating away mid-wait: the next command sees the new one.
|
|
267
|
+
if (!/navigat|destroyed|closed/i.test(String(err)))
|
|
268
|
+
throw err;
|
|
269
|
+
});
|
|
270
|
+
const now = Date.now();
|
|
271
|
+
const pending = [...this.#inflight.entries()].map(([r, at]) => `${r.method()} ${short(r.url())} (${((now - at) / 1000).toFixed(1)} s)`);
|
|
272
|
+
return { ms: now - started, pending };
|
|
273
|
+
}
|
|
274
|
+
async #busy() {
|
|
275
|
+
return this.page.evaluate(IN_PAGE.busy).catch((err) => {
|
|
276
|
+
// A page navigating away mid-check is not busy; the wait goes on with the new one.
|
|
277
|
+
if (/navigat|destroyed|closed/i.test(String(err)))
|
|
278
|
+
return false;
|
|
279
|
+
throw err;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/** The page as text, each element with a ref (`[ref=e5]`) the actions take. */
|
|
283
|
+
async snapshot(maxLines = 300) {
|
|
284
|
+
const text = await this.page.ariaSnapshot({ mode: 'ai' });
|
|
285
|
+
const lines = text.split('\n');
|
|
286
|
+
return lines.length > maxLines
|
|
287
|
+
? [...lines.slice(0, maxLines), `… ${lines.length - maxLines} more lines`].join('\n')
|
|
288
|
+
: text;
|
|
289
|
+
}
|
|
290
|
+
/** A ref from the last snapshot (`e5`, `@e5`), or a Playwright selector. */
|
|
291
|
+
locate(target) {
|
|
292
|
+
return isRef(target)
|
|
293
|
+
? this.page.getByRef(target.replace(/^@/, ''))
|
|
294
|
+
: this.page.locator(target);
|
|
295
|
+
}
|
|
296
|
+
async setView(opts) {
|
|
297
|
+
if (opts.width !== undefined) {
|
|
298
|
+
const size = this.page.viewportSize() ?? PANEL;
|
|
299
|
+
if (size.width !== opts.width) {
|
|
300
|
+
await this.page.setViewportSize({ width: opts.width, height: size.height });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (opts.dark !== undefined) {
|
|
304
|
+
await this.page.emulateMedia({ colorScheme: opts.dark ? 'dark' : 'light' });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/** The page at its current width and scheme (or those asked for), into `file` (or parts of it). */
|
|
308
|
+
async screenshot(file, opts = {}) {
|
|
309
|
+
await this.setView(opts);
|
|
310
|
+
await this.settle(3000);
|
|
311
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
312
|
+
const common = { animations: 'disabled', caret: 'hide' };
|
|
313
|
+
const height = await this.page.evaluate(IN_PAGE.height);
|
|
314
|
+
if (opts.target) {
|
|
315
|
+
await this.locate(opts.target).screenshot({ ...common, path: file });
|
|
316
|
+
return { files: [file], height };
|
|
317
|
+
}
|
|
318
|
+
if (opts.area === 'viewport') {
|
|
319
|
+
await this.page.screenshot({ ...common, path: file });
|
|
320
|
+
return { files: [file], height };
|
|
321
|
+
}
|
|
322
|
+
const width = this.page.viewportSize()?.width ?? PANEL.width;
|
|
323
|
+
const parts = opts.area === 'full' ? Math.min(MAX_PARTS, Math.ceil(height / SHOT_HEIGHT)) : 1;
|
|
324
|
+
const files = [];
|
|
325
|
+
for (let i = 0; i < parts; i++) {
|
|
326
|
+
const path = parts > 1 ? file.replace(/(\.png)?$/i, `-${i + 1}.png`) : file;
|
|
327
|
+
const top = i * SHOT_HEIGHT;
|
|
328
|
+
await this.page.screenshot({
|
|
329
|
+
...common,
|
|
330
|
+
path,
|
|
331
|
+
fullPage: true,
|
|
332
|
+
clip: {
|
|
333
|
+
x: 0,
|
|
334
|
+
y: top,
|
|
335
|
+
width,
|
|
336
|
+
height: Math.max(1, Math.min(SHOT_HEIGHT, height - top)),
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
files.push(path);
|
|
340
|
+
}
|
|
341
|
+
return { files, height };
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* The page's first screen at PREVIEW's size, light, into `file`: the picture its card shows.
|
|
345
|
+
* The window is put back as it was.
|
|
346
|
+
*/
|
|
347
|
+
async preview(file) {
|
|
348
|
+
const size = this.page.viewportSize() ?? PANEL;
|
|
349
|
+
await this.page.setViewportSize(PREVIEW);
|
|
350
|
+
await this.page.emulateMedia({ colorScheme: 'light' });
|
|
351
|
+
try {
|
|
352
|
+
await this.settle(3000);
|
|
353
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
354
|
+
await this.page.screenshot({ animations: 'disabled', caret: 'hide', path: file });
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
await this.page.setViewportSize(size);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/** Whether the page scrolls sideways at its width, and the elements furthest out. */
|
|
361
|
+
async overflow() {
|
|
362
|
+
return this.page.evaluate(IN_PAGE.overflow);
|
|
363
|
+
}
|
|
364
|
+
/** A page that drew nothing: no text and no picture. */
|
|
365
|
+
async empty() {
|
|
366
|
+
return this.page.evaluate(IN_PAGE.empty);
|
|
367
|
+
}
|
|
368
|
+
async close() {
|
|
369
|
+
await this.context.close().catch((err) => {
|
|
370
|
+
console.warn('zen page: closing the browser context failed; dropped', err);
|
|
371
|
+
});
|
|
372
|
+
if (this.#owned) {
|
|
373
|
+
await this.browser.close().catch((err) => {
|
|
374
|
+
console.warn('zen page: closing the browser failed; dropped', err);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/** An error as one line: Playwright's carry a call log after the first lines. */
|
|
380
|
+
export function errorText(err) {
|
|
381
|
+
const text = err instanceof Error ? err.message : String(err);
|
|
382
|
+
const head = text.split(/\n\s*Call log:/)[0] ?? text;
|
|
383
|
+
return head.split('\n').slice(0, 3).join(' ').replace(/\s+/g, ' ').trim();
|
|
384
|
+
}
|
|
385
|
+
/** What a function that failed said: its error and the end of its stderr. */
|
|
386
|
+
function callDetail(body) {
|
|
387
|
+
try {
|
|
388
|
+
const parsed = JSON.parse(body.toString('utf8'));
|
|
389
|
+
const said = [parsed.error, parsed.stderr?.trim().split('\n').slice(-3).join(' | ')]
|
|
390
|
+
.filter(Boolean)
|
|
391
|
+
.join(' - ');
|
|
392
|
+
return said ? `: ${said.slice(0, 600)}` : '';
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
// Not JSON: the status says enough.
|
|
396
|
+
return '';
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/** A URL as worth reading: a local page's agent path, else the URL without its query. */
|
|
400
|
+
export function short(url) {
|
|
401
|
+
if (url.startsWith(PAGE_ORIGIN)) {
|
|
402
|
+
try {
|
|
403
|
+
return decodeURIComponent(url.slice(PAGE_ORIGIN.length));
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
return url.slice(PAGE_ORIGIN.length);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// A /v/ URL carries a token: never print it.
|
|
410
|
+
return url.replace(/\/v\/[^/]+\//, '/v/…/').replace(/[?#].*$/, '');
|
|
411
|
+
}
|
|
412
|
+
//# sourceMappingURL=session.js.map
|
package/dist/target.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type FileTrees } from '@zenera/engine';
|
|
2
|
+
export declare const SANDBOX_WORKDIR = "/workspace";
|
|
3
|
+
export interface Target {
|
|
4
|
+
/** what was asked for, for messages */
|
|
5
|
+
asked: string;
|
|
6
|
+
/** the pages: agent paths of local html files, or one URL */
|
|
7
|
+
pages: string[];
|
|
8
|
+
/** null for a URL */
|
|
9
|
+
trees: FileTrees | null;
|
|
10
|
+
/** the page folder's name: screenshots' folder */
|
|
11
|
+
name: string;
|
|
12
|
+
/** where screenshots go */
|
|
13
|
+
outDir: string;
|
|
14
|
+
}
|
|
15
|
+
/** Whether `cwd` is in a zen sandbox's workspace (each command there has its own /tmp). */
|
|
16
|
+
export declare const inSandbox: (cwd: string) => boolean;
|
|
17
|
+
export declare function resolveTarget(asked: string, cwd: string, root?: string): Target;
|
|
18
|
+
/** zen's runtime library for a page's functions, when this is not a sandbox that has it. */
|
|
19
|
+
export declare function pythonPath(): string[];
|
|
20
|
+
/** A path as worth printing: relative to the cwd when under it. */
|
|
21
|
+
export declare function shown(path: string, cwd: string): string;
|
|
22
|
+
//# sourceMappingURL=target.d.ts.map
|
package/dist/target.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { RUNTIME_PYTHON, RUNTIME_SOURCE, usageError } from '@zenera/engine';
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// What `zen page` was pointed at, and where its files go
|
|
6
|
+
//
|
|
7
|
+
// A page folder (`/workspace/pages/todo`: its index.html, then every other built *.html), one
|
|
8
|
+
// html file, or a URL. A local page is served from its workspace: `/workspace` inside a zen
|
|
9
|
+
// sandbox (with `/assets`), else the current folder (or --root) on a person's machine, its
|
|
10
|
+
// paths then being the machine's own. Screenshots go under the workspace's `.tmp/page-check/`.
|
|
11
|
+
//
|
|
12
|
+
// Main: resolveTarget, inSandbox, pythonPath, shown.
|
|
13
|
+
// Used by: @zenera/cli `zen page` (commands/page.ts, page/daemon.ts).
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
export const SANDBOX_WORKDIR = '/workspace';
|
|
16
|
+
const ASSETS = '/assets';
|
|
17
|
+
const under = (at, base) => at === base || at.startsWith(base + sep);
|
|
18
|
+
/** Whether `cwd` is in a zen sandbox's workspace (each command there has its own /tmp). */
|
|
19
|
+
export const inSandbox = (cwd) => existsSync(SANDBOX_WORKDIR) && under(cwd, SANDBOX_WORKDIR);
|
|
20
|
+
/** The workspace a local page is served from. */
|
|
21
|
+
function rootOf(abs, cwd, root) {
|
|
22
|
+
if (root)
|
|
23
|
+
return resolve(cwd, root);
|
|
24
|
+
if (existsSync(SANDBOX_WORKDIR) && (under(abs, SANDBOX_WORKDIR) || under(abs, ASSETS))) {
|
|
25
|
+
return SANDBOX_WORKDIR;
|
|
26
|
+
}
|
|
27
|
+
if (under(abs, cwd))
|
|
28
|
+
return cwd;
|
|
29
|
+
return statSync(abs).isDirectory() ? abs : dirname(abs);
|
|
30
|
+
}
|
|
31
|
+
function pagesIn(dir) {
|
|
32
|
+
const html = readdirSync(dir)
|
|
33
|
+
.filter((f) => /\.html?$/i.test(f))
|
|
34
|
+
.sort((a, b) => (a === 'index.html' ? -1 : b === 'index.html' ? 1 : a.localeCompare(b)));
|
|
35
|
+
return html.map((f) => join(dir, f));
|
|
36
|
+
}
|
|
37
|
+
export function resolveTarget(asked, cwd, root) {
|
|
38
|
+
if (/^https?:\/\//i.test(asked)) {
|
|
39
|
+
const base = inSandbox(cwd) ? SANDBOX_WORKDIR : cwd;
|
|
40
|
+
const name = new URL(asked).pathname.split('/').filter(Boolean).slice(-2, -1)[0] ?? 'page';
|
|
41
|
+
return {
|
|
42
|
+
asked,
|
|
43
|
+
pages: [asked],
|
|
44
|
+
trees: null,
|
|
45
|
+
name,
|
|
46
|
+
outDir: join(base, '.tmp', 'page-check', name),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const abs = resolve(cwd, asked);
|
|
50
|
+
if (!existsSync(abs))
|
|
51
|
+
throw usageError(`no such file or folder: ${abs}`);
|
|
52
|
+
const top = rootOf(abs, cwd, root);
|
|
53
|
+
let pages;
|
|
54
|
+
let folder;
|
|
55
|
+
if (statSync(abs).isDirectory()) {
|
|
56
|
+
folder = abs;
|
|
57
|
+
pages = pagesIn(abs);
|
|
58
|
+
if (!pages.length) {
|
|
59
|
+
throw usageError(`no built page in ${abs}`, 'build it first: node /skills/html-page/scripts/build.ts <folder>');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (!/^\.html?$/i.test(extname(abs)))
|
|
64
|
+
throw usageError(`not an html page: ${abs}`);
|
|
65
|
+
folder = dirname(abs);
|
|
66
|
+
pages = [abs];
|
|
67
|
+
}
|
|
68
|
+
const sandboxed = top === SANDBOX_WORKDIR;
|
|
69
|
+
if (!under(abs, top) && !(sandboxed && under(abs, ASSETS))) {
|
|
70
|
+
throw usageError(`${abs} is outside ${top}`, 'name its workspace with --root');
|
|
71
|
+
}
|
|
72
|
+
const name = basename(folder) || 'page';
|
|
73
|
+
return {
|
|
74
|
+
asked,
|
|
75
|
+
pages,
|
|
76
|
+
trees: {
|
|
77
|
+
workspace: top,
|
|
78
|
+
workdir: top,
|
|
79
|
+
...(sandboxed && existsSync(ASSETS) ? { assets: ASSETS } : {}),
|
|
80
|
+
// As a chat shows them: the agent's scratch folder is readable.
|
|
81
|
+
dotted: [join(top, '.tmp')],
|
|
82
|
+
},
|
|
83
|
+
name,
|
|
84
|
+
outDir: join(top, '.tmp', 'page-check', name),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** zen's runtime library for a page's functions, when this is not a sandbox that has it. */
|
|
88
|
+
export function pythonPath() {
|
|
89
|
+
return existsSync(RUNTIME_PYTHON) ? [] : [join(RUNTIME_SOURCE, 'python')];
|
|
90
|
+
}
|
|
91
|
+
/** A path as worth printing: relative to the cwd when under it. */
|
|
92
|
+
export function shown(path, cwd) {
|
|
93
|
+
const rel = relative(cwd, path);
|
|
94
|
+
return rel && !rel.startsWith('..') ? rel : path;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=target.js.map
|
package/dist/widths.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const WIDTH_PRESETS: {
|
|
2
|
+
/** the chat's side panel, and a phone: compact, everything stacked */
|
|
3
|
+
readonly panel: 400;
|
|
4
|
+
/** a wide panel or a tablet: full size, a Split still one column */
|
|
5
|
+
readonly 'wide-panel': 640;
|
|
6
|
+
/** a full browser tab: a Split side by side, grids spread out */
|
|
7
|
+
readonly tab: 1280;
|
|
8
|
+
};
|
|
9
|
+
export type WidthPreset = keyof typeof WIDTH_PRESETS;
|
|
10
|
+
/** What a check looks at: every layout the kit has, the panel first. */
|
|
11
|
+
export declare const DEFAULT_WIDTHS: readonly number[];
|
|
12
|
+
/** A preset's name or a number of px. */
|
|
13
|
+
export declare function widthOf(text: string): number;
|
|
14
|
+
/** A comma-separated list of widths; DEFAULT_WIDTHS when none is given. */
|
|
15
|
+
export declare function widthsOf(text: string | undefined): number[];
|
|
16
|
+
/** The preset a width is, for file names and messages: `panel`, or `900`. */
|
|
17
|
+
export declare function widthName(px: number): string;
|
|
18
|
+
//# sourceMappingURL=widths.d.ts.map
|
package/dist/widths.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { usageError } from '@zenera/engine';
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// The widths a page is looked at
|
|
4
|
+
//
|
|
5
|
+
// Named after where the chat shows a page, at the widths the html-page kit's layout changes
|
|
6
|
+
// (kit/theme.css): under 520 px it goes compact; from 860 px a Split puts list and detail side
|
|
7
|
+
// by side. One width on each side of both covers every layout the kit has.
|
|
8
|
+
//
|
|
9
|
+
// Main: WIDTH_PRESETS, DEFAULT_WIDTHS, widthOf, widthsOf, widthName.
|
|
10
|
+
// Used by: report.ts (the check's widths); @zenera/cli `zen page` (--widths, --width, resize).
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export const WIDTH_PRESETS = {
|
|
13
|
+
/** the chat's side panel, and a phone: compact, everything stacked */
|
|
14
|
+
panel: 400,
|
|
15
|
+
/** a wide panel or a tablet: full size, a Split still one column */
|
|
16
|
+
'wide-panel': 640,
|
|
17
|
+
/** a full browser tab: a Split side by side, grids spread out */
|
|
18
|
+
tab: 1280,
|
|
19
|
+
};
|
|
20
|
+
/** What a check looks at: every layout the kit has, the panel first. */
|
|
21
|
+
export const DEFAULT_WIDTHS = Object.values(WIDTH_PRESETS);
|
|
22
|
+
const MIN_WIDTH = 200;
|
|
23
|
+
const MAX_WIDTH = 3840;
|
|
24
|
+
/** A preset's name or a number of px. */
|
|
25
|
+
export function widthOf(text) {
|
|
26
|
+
const name = text.trim().toLowerCase();
|
|
27
|
+
if (name in WIDTH_PRESETS)
|
|
28
|
+
return WIDTH_PRESETS[name];
|
|
29
|
+
const px = Number(name.replace(/px$/, ''));
|
|
30
|
+
if (!Number.isInteger(px) || px < MIN_WIDTH || px > MAX_WIDTH) {
|
|
31
|
+
throw usageError(`not a width: "${text}"`, `a preset (${Object.keys(WIDTH_PRESETS).join(', ')}) or px from ${MIN_WIDTH} to ${MAX_WIDTH}`);
|
|
32
|
+
}
|
|
33
|
+
return px;
|
|
34
|
+
}
|
|
35
|
+
/** A comma-separated list of widths; DEFAULT_WIDTHS when none is given. */
|
|
36
|
+
export function widthsOf(text) {
|
|
37
|
+
if (text === undefined)
|
|
38
|
+
return [...DEFAULT_WIDTHS];
|
|
39
|
+
const out = text
|
|
40
|
+
.split(',')
|
|
41
|
+
.filter((w) => w.trim())
|
|
42
|
+
.map(widthOf);
|
|
43
|
+
if (!out.length)
|
|
44
|
+
throw usageError('--widths names no width');
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** The preset a width is, for file names and messages: `panel`, or `900`. */
|
|
48
|
+
export function widthName(px) {
|
|
49
|
+
return Object.entries(WIDTH_PRESETS).find(([, w]) => w === px)?.[0] ?? String(px);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=widths.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@zenera/browser",
|
|
3
|
+
"version": "1.3.39",
|
|
4
|
+
"description": "An html page in a real browser, served as a zen chat serves it: checked for errors, driven, photographed.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"playwright",
|
|
7
|
+
"browser",
|
|
8
|
+
"screenshots",
|
|
9
|
+
"agents"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"author": "Andrey Ryabov",
|
|
16
|
+
"homepage": "https://github.com/zenera-ai/ZeneraNeo#readme",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/zenera-ai/ZeneraNeo.git",
|
|
20
|
+
"directory": "packages/browser"
|
|
21
|
+
},
|
|
22
|
+
"bugs": "https://github.com/zenera-ai/ZeneraNeo/issues",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"!dist/**/*.map"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=24"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -b",
|
|
40
|
+
"clean": "tsc -b --clean && rm -rf dist",
|
|
41
|
+
"prepack": "tsc -b"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@zenera/engine": "^1.3.39",
|
|
45
|
+
"@zenera/sandbox": "^1.3.39",
|
|
46
|
+
"playwright-core": "1.65.1"
|
|
47
|
+
}
|
|
48
|
+
}
|