@owlmeans/llm-reader-playwright 0.1.22-rc.0 → 0.2.0
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 +67 -6
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/llm-reader-playwright/SKILL.md +62 -15
- package/build/consts.d.ts +2 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +2 -0
- package/build/consts.js.map +1 -1
- package/build/renderer/consts.local.d.ts +5 -0
- package/build/renderer/consts.local.d.ts.map +1 -0
- package/build/renderer/consts.local.js +9 -0
- package/build/renderer/consts.local.js.map +1 -0
- package/build/renderer/snapshot.d.ts +8 -0
- package/build/renderer/snapshot.d.ts.map +1 -0
- package/build/renderer/snapshot.js +50 -0
- package/build/renderer/snapshot.js.map +1 -0
- package/build/renderer/types.d.ts +10 -1
- package/build/renderer/types.d.ts.map +1 -1
- package/build/renderer.d.ts +2 -1
- package/build/renderer.d.ts.map +1 -1
- package/build/renderer.js +71 -4
- package/build/renderer.js.map +1 -1
- package/package.json +8 -7
- package/src/consts.ts +3 -0
- package/src/renderer/consts.local.ts +9 -0
- package/src/renderer/snapshot.ts +43 -0
- package/src/renderer/types.ts +10 -1
- package/src/renderer.ts +68 -6
- package/tests/collect.spec.ts +100 -0
package/README.md
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
# @owlmeans/llm-reader-playwright
|
|
2
2
|
|
|
3
3
|
A Playwright renderer for `@owlmeans/llm-reader`: pages run their scripts before they are read, and
|
|
4
|
-
the design analysis gets computed styles, custom properties, block geometry and a screenshot.
|
|
4
|
+
the design analysis gets computed styles, custom properties, block geometry and a screenshot. Every
|
|
5
|
+
request a rendered page makes passes the reader's address guard, goes through the reader's proxy
|
|
6
|
+
lease, and — given the reader's pinned `fetch` — is fetched through it rather than re-resolved by the
|
|
7
|
+
browser. Local bundles (an uploaded prototype, a collected page) render from disk.
|
|
5
8
|
|
|
6
9
|
## Installation
|
|
7
10
|
|
|
8
11
|
```bash
|
|
9
|
-
bun add @owlmeans/llm-reader-playwright@^0.
|
|
12
|
+
bun add @owlmeans/llm-reader-playwright@^0.2.0 playwright
|
|
10
13
|
bunx playwright install chromium
|
|
11
14
|
```
|
|
12
15
|
|
|
16
|
+
`playwright` is a peer: the renderer uses the browsers installed beside it.
|
|
17
|
+
|
|
13
18
|
## Usage
|
|
14
19
|
|
|
15
20
|
```typescript
|
|
16
21
|
import { createLlmReader, createLocalBundlePlugin, createProxyPlugin } from '@owlmeans/llm-reader'
|
|
17
22
|
import { createPlaywrightRenderer, makePlaywrightFetchPlugin } from '@owlmeans/llm-reader-playwright'
|
|
23
|
+
import { createPinnedFetch } from '@owlmeans/file-streams/fetch'
|
|
18
24
|
|
|
19
25
|
const renderer = createPlaywrightRenderer()
|
|
20
26
|
const reader = createLlmReader({ renderer, plugins: [createProxyPlugin({ proxies })], models })
|
|
@@ -28,18 +34,63 @@ createLlmReader({ plugins: [createProxyPlugin({ proxies }), makePlaywrightFetchP
|
|
|
28
34
|
// A local prototype (an uploaded home.html with its css and pictures), rendered from disk:
|
|
29
35
|
const bundle = createLocalBundlePlugin({ root: '/uploads/prototype' })
|
|
30
36
|
await createLlmReader({ renderer, plugins: [bundle], models }).design(bundle.urlOf('home.html'))
|
|
37
|
+
|
|
38
|
+
// A bundle `collect` wrote renders offline: its bundle.json answers the original external URLs from disk.
|
|
39
|
+
// With a pinned fetch, live sub-requests are fetched through it instead of Chromium re-resolving the host:
|
|
40
|
+
createLlmReader({ renderer, fetch: createPinnedFetch(), models })
|
|
41
|
+
|
|
42
|
+
await reader.close() // closes the browser the renderer launched
|
|
31
43
|
```
|
|
32
44
|
|
|
33
45
|
The browser goes through the reader's proxy lease (SOCKS proxies through the reader's bridge), and
|
|
34
46
|
every request a page makes passes the reader's address guard; refused ones are listed in
|
|
35
|
-
`RenderedPage.blocked`.
|
|
47
|
+
`RenderedPage.blocked`. Given the reader's injected `fetch`, every guarded GET/HEAD is fulfilled
|
|
48
|
+
through it (`route.fulfill`), other methods are refused. `collect` asks for a `snapshot`: rules a
|
|
49
|
+
script put only into the CSSOM are written into `<style>` elements before the DOM is serialized.
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
| Option | Default | Purpose |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `browser` | Chromium, launched headless on first use | A `Browser`, or a function returning one; a browser passed in is never closed by the renderer. |
|
|
56
|
+
| `launch` | — | Playwright `LaunchOptions` for the browser the renderer launches. |
|
|
57
|
+
| `viewport` | `DEFAULT_VIEWPORT` (1280×800) | The viewport pages render and are screenshot in. |
|
|
58
|
+
| `timeout` | `DEFAULT_RENDER_TIMEOUT_MS` (30 s) | Navigation deadline; a render request's own `timeout` wins. |
|
|
59
|
+
| `waitUntil` · `settle` | `load` · `DEFAULT_SETTLE_MS` (3 s) | When navigation counts as done, then how long the page may keep loading before it is read. |
|
|
60
|
+
| `userAgent` | Playwright's | The browser's user agent. |
|
|
61
|
+
| `bundles` | `[]` | Local bundles (`createLocalBundlePlugin`) whose origins and manifest URLs are answered from disk. |
|
|
62
|
+
| `fetch` | — | A pinned `fetch` guarded sub-requests are fulfilled through; a render request's own `fetch` wins. |
|
|
63
|
+
| `maxFulfilBytes` | `DEFAULT_MAX_FULFIL_BYTES` (16 MiB) | The largest sub-request answer fulfilled through `fetch`; a larger one is aborted. |
|
|
64
|
+
|
|
65
|
+
## Security and limits
|
|
66
|
+
|
|
67
|
+
- One browser context per page, closed after it: downloads off, service workers blocked.
|
|
68
|
+
- Every sub-request is checked by the reader's address guard; a refused one is aborted
|
|
69
|
+
(`blockedbyclient`) and listed in `RenderedPage.blocked`.
|
|
70
|
+
- With a pinned `fetch`, only GET and HEAD are carried; any other method is refused. Redirects go
|
|
71
|
+
back to the browser, so each hop is guarded again.
|
|
72
|
+
- Bundle files are served from disk under their synthetic origin — never resolved, never proxied.
|
|
73
|
+
- Through a proxy lease the injected `fetch` is not used: the proxy carries the requests.
|
|
36
74
|
|
|
37
75
|
## API
|
|
38
76
|
|
|
39
77
|
| Export | Purpose |
|
|
40
78
|
|---|---|
|
|
41
|
-
| `createPlaywrightRenderer(options)` | `render({ url, lease?, guard?, styles?, screenshot?, bundle? })` → `RenderedPage`; `close()
|
|
42
|
-
| `makePlaywrightFetchPlugin(renderer, { when? })` | A reader fetch plugin that renders page requests. |
|
|
79
|
+
| `createPlaywrightRenderer(options?)` | A `PlaywrightRenderer` (`PageRenderer`): `render({ url, lease?, guard?, styles?, screenshot?, signal?, timeout?, bundle?, fetch?, snapshot? })` → `RenderedPage`; `close()` shuts down a browser it launched. |
|
|
80
|
+
| `makePlaywrightFetchPlugin(renderer, { when? })` | A reader fetch plugin that renders page requests (every `purpose: 'page'` request, or those `when` picks); put it after the proxy plugin. |
|
|
81
|
+
| `DEFAULT_VIEWPORT`, `DEFAULT_RENDER_TIMEOUT_MS`, `DEFAULT_SETTLE_MS`, `DEFAULT_MAX_FULFIL_BYTES`, `SCREENSHOT_QUALITY`, `PROBE_ELEMENTS` | Defaults: 1280×800, 30 s, 3 s, 16 MiB, JPEG quality 70, at most 4000 elements sampled. |
|
|
82
|
+
| `PlaywrightRendererOptions`, `PlaywrightRenderer`, `PlaywrightFetchPluginOptions`, `ProbeResult` | Types. |
|
|
83
|
+
|
|
84
|
+
The package has one entry point; there are no subpath exports.
|
|
85
|
+
|
|
86
|
+
## Common pitfalls
|
|
87
|
+
|
|
88
|
+
- The fetch plugin hands the renderer no per-request `bundle` or `fetch`: configure `bundles` and
|
|
89
|
+
`fetch` on the renderer when the plugin renders such pages.
|
|
90
|
+
- Chromium sends loopback targets direct, around a proxy, unless launched with
|
|
91
|
+
`--proxy-bypass-list=<-loopback>`.
|
|
92
|
+
- Chromium's own local-network rules may stop an `https` bundle page from reaching a loopback host
|
|
93
|
+
the guard allowed.
|
|
43
94
|
|
|
44
95
|
## Tests
|
|
45
96
|
|
|
@@ -48,6 +99,16 @@ bun test ./tests
|
|
|
48
99
|
```
|
|
49
100
|
|
|
50
101
|
Gated on an installed Chromium; the design spec also on `ANTHROPIC_SECRET` or `OPENAI_SECRET`.
|
|
102
|
+
`collect.spec.ts` renders a collected bundle with its servers stopped, snapshots an app shell, and
|
|
103
|
+
fulfils through file-streams' pinned fetch (reached by a test-only relative import).
|
|
104
|
+
|
|
105
|
+
## Related packages
|
|
106
|
+
|
|
107
|
+
- [`@owlmeans/llm-reader`](../llm-reader) — the reader, its `PageRenderer` seam, proxies, guard and `collect`
|
|
108
|
+
- [`@owlmeans/file-streams`](../file-streams) — `@owlmeans/file-streams/fetch`: the pinned `fetch` a reader hands the renderer
|
|
109
|
+
- [`@owlmeans/web-research`](../web-research) — its design pipeline renders a bundle offline with a borrowed renderer
|
|
110
|
+
|
|
111
|
+
The `llm-reader-playwright` skill covers the same package for agents.
|
|
51
112
|
|
|
52
113
|
<!-- owlmeans:agent-guidance:start -->
|
|
53
114
|
## Agent guidance
|
|
@@ -57,7 +118,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
57
118
|
your project's skill store (`.agents/skills/`):
|
|
58
119
|
|
|
59
120
|
```sh
|
|
60
|
-
npx @owlmeans/agent-skills@^0.
|
|
121
|
+
npx @owlmeans/agent-skills@^0.2.0
|
|
61
122
|
```
|
|
62
123
|
|
|
63
124
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 3,
|
|
3
3
|
"package": "@owlmeans/llm-reader-playwright",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"generatedAt": "2026-11-
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"generatedAt": "2026-11-15T13:38:38.682Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: llm-reader-playwright
|
|
3
|
-
description: How to use @owlmeans/llm-reader-playwright — a Playwright PageRenderer for @owlmeans/llm-reader that runs a page's scripts, samples computed styles by role, reads custom properties and block geometry, takes a screenshot, routes the browser through the reader's proxy lease (SOCKS through the bridge)
|
|
3
|
+
description: How to use @owlmeans/llm-reader-playwright — a Playwright PageRenderer for @owlmeans/llm-reader that runs a page's scripts, samples computed styles by role, reads custom properties and block geometry, takes a screenshot, snapshots an app shell's DOM with its CSSOM-only rules inlined, routes the browser through the reader's proxy lease (SOCKS through the bridge), guards every request it makes and, given the reader's pinned fetch, fulfils every guarded sub-request through it instead of letting Chromium resolve the host again; serves local bundles (uploaded prototypes, and collected bundles with their bundle.json externals) from disk; and a fetch plugin that renders inside the reader's chain. Auto-invoked when importing createPlaywrightRenderer or makePlaywrightFetchPlugin.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,12 +8,13 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/llm-reader-playwright
|
|
9
9
|
|
|
10
10
|
**Layer:** Server (drives a browser)
|
|
11
|
-
**Install:** `"@owlmeans/llm-reader-playwright": "^0.
|
|
11
|
+
**Install:** `"@owlmeans/llm-reader-playwright": "^0.2.0"` in `dependencies`, plus the
|
|
12
12
|
`playwright` **peer** — the consumer's installed browsers are used (`bunx playwright install chromium`)
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
15
|
import { createLlmReader, createLocalBundlePlugin, createProxyPlugin } from '@owlmeans/llm-reader'
|
|
16
16
|
import { createPlaywrightRenderer } from '@owlmeans/llm-reader-playwright'
|
|
17
|
+
import { createPinnedFetch } from '@owlmeans/file-streams/fetch'
|
|
17
18
|
|
|
18
19
|
const renderer = createPlaywrightRenderer()
|
|
19
20
|
const reader = createLlmReader({ renderer, plugins: [createProxyPlugin({ proxies })], models })
|
|
@@ -23,35 +24,78 @@ await reader.page('https://spa.example.com') // an app shell is re-read re
|
|
|
23
24
|
const bundle = createLocalBundlePlugin({ root: '/uploads/prototype' })
|
|
24
25
|
const local = createLlmReader({ renderer, plugins: [bundle], models })
|
|
25
26
|
await local.design(bundle.urlOf('home.html')) // the prototype rendered from disk: styles + screenshot
|
|
27
|
+
|
|
28
|
+
const pinned = createLlmReader({ renderer, fetch: createPinnedFetch(), models })
|
|
29
|
+
await pinned.collect('https://spa.example.com', { sink }) // an app shell saved as its rendered snapshot
|
|
30
|
+
await reader.close() // closes the browser the renderer launched
|
|
26
31
|
```
|
|
27
32
|
|
|
28
33
|
## Key exports
|
|
29
34
|
|
|
30
35
|
| Export | Description |
|
|
31
36
|
|---|---|
|
|
32
|
-
| `createPlaywrightRenderer({ browser?, launch?, viewport
|
|
33
|
-
| `makePlaywrightFetchPlugin(renderer, { when? })` | A reader fetch plugin that renders page requests (all, or those `when` picks). Place it after the proxy plugin so it renders through the chosen lease. |
|
|
34
|
-
| `PlaywrightRendererOptions`, `
|
|
37
|
+
| `createPlaywrightRenderer({ browser?, launch?, viewport?, timeout?, waitUntil?, settle?, userAgent?, bundles?, fetch?, maxFulfilBytes? })` → `PlaywrightRenderer` | A `PageRenderer`: `render({ url, lease?, guard?, styles?, screenshot?, signal?, timeout?, bundle?, fetch?, snapshot? })` → `RenderedPage` (HTML after scripts, final URL, status, `styles`, `variables`, `blocks`, `viewport`, JPEG `screenshot`, `blocked`); `close()` shuts down a browser it launched (one passed in `browser` is left open). |
|
|
38
|
+
| `makePlaywrightFetchPlugin(renderer, { when? })` | A reader fetch plugin that renders page requests (all `purpose: 'page'` requests, or those `when` picks) and answers them as `text/html` with `rendered` set. Place it after the proxy plugin so it renders through the chosen lease. |
|
|
39
|
+
| `PlaywrightRendererOptions`, `PlaywrightFetchPluginOptions`, `ProbeResult` | Option and probe types. |
|
|
40
|
+
| `DEFAULT_VIEWPORT`, `DEFAULT_RENDER_TIMEOUT_MS`, `DEFAULT_SETTLE_MS`, `DEFAULT_MAX_FULFIL_BYTES`, `SCREENSHOT_QUALITY`, `PROBE_ELEMENTS` | 1280×800, 30 s navigation, 3 s to go network-idle, 16 MiB per fulfilled answer, JPEG quality 70, 4000 sampled elements. |
|
|
35
41
|
|
|
36
42
|
## Rules
|
|
37
43
|
|
|
38
|
-
- **One browser context per page**, closed after: viewport set, downloads off, service workers
|
|
44
|
+
- **One browser context per page**, closed after: viewport set, downloads off, service workers
|
|
45
|
+
blocked. Chromium is launched headless on first use unless `browser` gives one.
|
|
39
46
|
- **Proxy**: the context's proxy is the lease's `endpoint()` — the upstream HTTP(S) proxy, or the
|
|
40
47
|
reader's SOCKS bridge, which answers a 407 challenge so Chromium sends the route credentials
|
|
41
48
|
(Chromium has no SOCKS authentication of its own). Chromium sends loopback targets direct unless
|
|
42
49
|
launched with `--proxy-bypass-list=<-loopback>`.
|
|
43
50
|
- **Guard**: every request of the page goes through the reader's address guard (a direct render
|
|
44
51
|
resolves names, a proxied one checks literal addresses); refused ones are aborted and listed in
|
|
45
|
-
`RenderedPage.blocked`.
|
|
46
|
-
- **
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
`RenderedPage.blocked`. `data:` and `blob:` URLs pass.
|
|
53
|
+
- **Pinned sub-requests**: with an injected `fetch` (the render request's, set by a reader that has
|
|
54
|
+
one, or the options'), a request that passed the guard is fetched through it with
|
|
55
|
+
`redirect: 'manual'` and fulfilled with its status, headers (minus encoding/length) and body read
|
|
56
|
+
whole under `maxFulfilBytes` — a redirect goes back to Chromium, whose next request is guarded
|
|
57
|
+
again. Only GET/HEAD; another method, or a refusal of the fetch (`refused === true`), is aborted
|
|
58
|
+
and listed in `blocked`; a network failure is aborted unlisted. Without a fetch, a guarded request
|
|
59
|
+
is `route.continue()`d — Chromium resolves the host again. A lease and a fetch do not mix: through
|
|
60
|
+
a proxy the lease carries the requests.
|
|
61
|
+
- **Snapshots**: `snapshot: true` (what `collect` asks for) writes rules a script put only into the
|
|
62
|
+
CSSOM — `insertRule` on a `<style>`, adopted stylesheets — into `<style>` elements before the DOM
|
|
63
|
+
is serialized, so the HTML keeps its look without its scripts.
|
|
64
|
+
- **Local bundles**: a request a bundle in `bundles` (or the render request's `bundle`, which the
|
|
65
|
+
reader sets for a bundle URL) `serves` — its synthetic origin, and for a collected bundle the
|
|
66
|
+
manifest's original URLs and the page origin's paths present on disk — is fulfilled from the
|
|
67
|
+
bundle (`page.route`): never resolved, never proxied; a missing file is a 404, a refused path is
|
|
68
|
+
aborted and listed in `blocked`. A collected bundle therefore renders offline. Everything else the
|
|
69
|
+
page loads still goes through the guard, so a prototype that pulls a picture from a private
|
|
70
|
+
address is refused as any page would be. Chromium's own local-network rules may still stop an
|
|
71
|
+
`https` bundle page from reaching a loopback host the guard allowed.
|
|
52
72
|
- **Probe**: computed styles of visible elements, by role (body, heading-1…6, link, button, input,
|
|
53
73
|
card, nav, header, footer, text), each property's dominant value weighted by on-screen area;
|
|
54
|
-
`:root` custom properties from readable stylesheets; blocks at least 80 px tall
|
|
74
|
+
`:root` custom properties from readable stylesheets; blocks at least 80 px tall and 30 % of the
|
|
75
|
+
viewport wide.
|
|
76
|
+
|
|
77
|
+
## Pitfalls
|
|
78
|
+
|
|
79
|
+
- `makePlaywrightFetchPlugin` hands the renderer no per-request `bundle` or `fetch`: give the
|
|
80
|
+
renderer `bundles` and `fetch` in its own options when the plugin renders such pages.
|
|
81
|
+
- Install Chromium where the reader runs (`bunx playwright install chromium`); `playwright` is a
|
|
82
|
+
peer, not bundled.
|
|
83
|
+
- `close()` on the reader closes the renderer too — the browser it launched (the next render
|
|
84
|
+
launches another); a browser passed in `browser` is never closed here.
|
|
85
|
+
|
|
86
|
+
## Maintaining
|
|
87
|
+
|
|
88
|
+
- The renderer fills `@owlmeans/llm-reader`'s `PageRenderer` seam; every `RenderRequest` field it
|
|
89
|
+
ignores is a hole: a new field there needs handling here and a spec.
|
|
90
|
+
- `probePage` and `inlineCssom` run INSIDE the page (serialized by Playwright): they may use nothing
|
|
91
|
+
from module scope.
|
|
92
|
+
- Specs (`bun test ./tests`, each self-skips without an installed Chromium): `render.spec` (an app
|
|
93
|
+
shell rendered with styles, variables and a screenshot; an HTTP proxy and SOCKS5 with credentials;
|
|
94
|
+
a private sub-request refused and reported; the fetch plugin; a linted DESIGN.md from computed
|
|
95
|
+
styles, gated on `ANTHROPIC_SECRET` or `OPENAI_SECRET`), `bundle.spec` (a prototype from disk, a
|
|
96
|
+
bundle URL through the reader with no proxy or DNS, a bundle page's external request still
|
|
97
|
+
guarded), `collect.spec` (a collected bundle rendering offline, an app shell collected as its
|
|
98
|
+
snapshot, guarded sub-requests fulfilled through file-streams' real pinned fetch).
|
|
55
99
|
|
|
56
100
|
## Depends On
|
|
57
101
|
|
|
@@ -60,8 +104,11 @@ await local.design(bundle.urlOf('home.html')) // the prototype rendered fro
|
|
|
60
104
|
## External docs
|
|
61
105
|
|
|
62
106
|
- https://playwright.dev/docs/api/class-browser#browser-new-context-option-proxy — per-context `proxy: { server, username, password, bypass }`; HTTP proxy authentication only (2026-11)
|
|
107
|
+
- https://playwright.dev/docs/api/class-route#route-fulfill — `route.fulfill({ status, headers, body })` takes a whole body (no stream); a fulfilled 3xx with `Location` is followed by Chromium as a new routed request (2026-11)
|
|
63
108
|
- https://playwright.dev/docs/api/class-browsercontext#browser-context-route — one `route('**/*')` handler per context answers every request: `route.fulfill({ status, contentType, body })` for a bundle file (no DNS, no proxy), `continue()` / `abort('blockedbyclient')` after the guard. Observed with Playwright 1.64's Chromium: an `https` page's `http://<IP>` sub-requests are not upgraded and do reach the route; a loopback one the guard allows can still be stopped by Chromium's local-network rules (2026-11)
|
|
64
109
|
|
|
65
110
|
## Related
|
|
66
111
|
|
|
67
|
-
- [[llm-reader]] — the reader, its proxies
|
|
112
|
+
- [[llm-reader]] (`@owlmeans/llm-reader`) — the reader, its proxies, its design analysis and `collect`
|
|
113
|
+
- [[file-streams]] (`@owlmeans/file-streams`) — the pinned `fetch` the reader hands the renderer
|
|
114
|
+
- [[web-research]] (`@owlmeans/web-research`) — its design pipeline borrows a renderer to read a bundle offline
|
package/build/consts.d.ts
CHANGED
|
@@ -11,4 +11,6 @@ export declare const DEFAULT_SETTLE_MS = 3000;
|
|
|
11
11
|
export declare const SCREENSHOT_QUALITY = 70;
|
|
12
12
|
/** Elements the style probe samples, at most. */
|
|
13
13
|
export declare const PROBE_ELEMENTS = 4000;
|
|
14
|
+
/** Bytes of one sub-request answer fulfilled through an injected fetch. */
|
|
15
|
+
export declare const DEFAULT_MAX_FULFIL_BYTES: number;
|
|
14
16
|
//# sourceMappingURL=consts.d.ts.map
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,eAAO,MAAM,gBAAgB;;;EAA8C,CAAA;AAE3E,+BAA+B;AAC/B,eAAO,MAAM,yBAAyB,QAAS,CAAA;AAE/C,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,OAAQ,CAAA;AAEtC,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC,iDAAiD;AACjD,eAAO,MAAM,cAAc,OAAO,CAAA"}
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,eAAO,MAAM,gBAAgB;;;EAA8C,CAAA;AAE3E,+BAA+B;AAC/B,eAAO,MAAM,yBAAyB,QAAS,CAAA;AAE/C,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,OAAQ,CAAA;AAEtC,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC,iDAAiD;AACjD,eAAO,MAAM,cAAc,OAAO,CAAA;AAElC,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB,QAAmB,CAAA"}
|
package/build/consts.js
CHANGED
|
@@ -8,4 +8,6 @@ export const DEFAULT_SETTLE_MS = 3_000;
|
|
|
8
8
|
export const SCREENSHOT_QUALITY = 70;
|
|
9
9
|
/** Elements the style probe samples, at most. */
|
|
10
10
|
export const PROBE_ELEMENTS = 4000;
|
|
11
|
+
/** Bytes of one sub-request answer fulfilled through an injected fetch. */
|
|
12
|
+
export const DEFAULT_MAX_FULFIL_BYTES = 16 * 1024 * 1024;
|
|
11
13
|
//# sourceMappingURL=consts.js.map
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;AAE3E,+BAA+B;AAC/B,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAE/C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAEtC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAEpC,iDAAiD;AACjD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA"}
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;AAE3E,+BAA+B;AAC/B,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAE/C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAEtC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAEpC,iDAAiD;AACjD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA;AAElC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Request headers a page's sub-request carries into an injected fetch. */
|
|
2
|
+
export declare const FULFIL_REQUEST_HEADERS: readonly string[];
|
|
3
|
+
/** Response headers never handed back to the browser: the body is decoded and whole. */
|
|
4
|
+
export declare const FULFIL_DROPPED_HEADERS: readonly string[];
|
|
5
|
+
//# sourceMappingURL=consts.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.d.ts","sourceRoot":"","sources":["../../src/renderer/consts.local.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAElD,CAAA;AAEF,wFAAwF;AACxF,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAElD,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Request headers a page's sub-request carries into an injected fetch. */
|
|
2
|
+
export const FULFIL_REQUEST_HEADERS = Object.freeze([
|
|
3
|
+
'accept', 'accept-language', 'user-agent', 'referer', 'range', 'if-none-match', 'if-modified-since', 'cache-control',
|
|
4
|
+
]);
|
|
5
|
+
/** Response headers never handed back to the browser: the body is decoded and whole. */
|
|
6
|
+
export const FULFIL_DROPPED_HEADERS = Object.freeze([
|
|
7
|
+
'content-encoding', 'content-length', 'transfer-encoding', 'connection', 'keep-alive',
|
|
8
|
+
]);
|
|
9
|
+
//# sourceMappingURL=consts.local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.js","sourceRoot":"","sources":["../../src/renderer/consts.local.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,sBAAsB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACrE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,eAAe;CACrH,CAAC,CAAA;AAEF,wFAAwF;AACxF,MAAM,CAAC,MAAM,sBAAsB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACrE,kBAAkB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY;CACtF,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs INSIDE the rendered page (serialized by Playwright — it may use nothing from this module's
|
|
3
|
+
* scope). Writes the rules a script put only into the CSSOM — `insertRule` on a `<style>` (CSS-in-JS)
|
|
4
|
+
* and adopted stylesheets — into `<style>` elements, so the serialized DOM keeps its look without the
|
|
5
|
+
* scripts. Answers how many rules it wrote.
|
|
6
|
+
*/
|
|
7
|
+
export declare const inlineCssom: () => number;
|
|
8
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/renderer/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAO,MAoC9B,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs INSIDE the rendered page (serialized by Playwright — it may use nothing from this module's
|
|
3
|
+
* scope). Writes the rules a script put only into the CSSOM — `insertRule` on a `<style>` (CSS-in-JS)
|
|
4
|
+
* and adopted stylesheets — into `<style>` elements, so the serialized DOM keeps its look without the
|
|
5
|
+
* scripts. Answers how many rules it wrote.
|
|
6
|
+
*/
|
|
7
|
+
export const inlineCssom = () => {
|
|
8
|
+
let written = 0;
|
|
9
|
+
const textOf = (sheet) => {
|
|
10
|
+
try {
|
|
11
|
+
return Array.from(sheet.cssRules).map(rule => rule.cssText).join('\n');
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined; // a cross-origin sheet keeps its own link
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
18
|
+
const owner = sheet.ownerNode;
|
|
19
|
+
if (!(owner instanceof HTMLStyleElement))
|
|
20
|
+
continue;
|
|
21
|
+
const text = textOf(sheet);
|
|
22
|
+
if (text == null || sheet.cssRules.length === 0)
|
|
23
|
+
continue;
|
|
24
|
+
// A `<style>` whose text already holds every rule is left as written.
|
|
25
|
+
const parsed = new CSSStyleSheet();
|
|
26
|
+
try {
|
|
27
|
+
parsed.replaceSync(owner.textContent ?? '');
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// unparseable text: its rules are whatever the CSSOM holds
|
|
31
|
+
}
|
|
32
|
+
if (parsed.cssRules.length === sheet.cssRules.length)
|
|
33
|
+
continue;
|
|
34
|
+
owner.textContent = text;
|
|
35
|
+
written += sheet.cssRules.length;
|
|
36
|
+
}
|
|
37
|
+
const adopted = document.adoptedStyleSheets ?? [];
|
|
38
|
+
for (const sheet of adopted) {
|
|
39
|
+
const text = textOf(sheet);
|
|
40
|
+
if (text == null || text === '')
|
|
41
|
+
continue;
|
|
42
|
+
const style = document.createElement('style');
|
|
43
|
+
style.setAttribute('data-owlmeans-adopted', '');
|
|
44
|
+
style.textContent = text;
|
|
45
|
+
document.head.appendChild(style);
|
|
46
|
+
written += sheet.cssRules.length;
|
|
47
|
+
}
|
|
48
|
+
return written;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/renderer/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAW,EAAE;IACtC,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,MAAM,MAAM,GAAG,CAAC,KAAoB,EAAsB,EAAE;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AI,IAAI,IAAI,IAAI,KAAK,EAAE;YAAE,SAAQ;QACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;QAC7C,KAAK,CAAC,YAAY,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAA;QAC/C,KAAK,CAAC,WAAW,GAAG,IAAI,CAAA;QACxB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QAChC,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAA;IAClC,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Browser, LaunchOptions } from 'playwright';
|
|
2
|
-
import type { FetchRequest, LocalBundle, PageRenderer, RenderedBlock, StyleSample } from '@owlmeans/llm-reader';
|
|
2
|
+
import type { FetchFunction, FetchRequest, LocalBundle, PageRenderer, RenderedBlock, StyleSample } from '@owlmeans/llm-reader';
|
|
3
3
|
export interface PlaywrightRendererOptions {
|
|
4
4
|
/** Your own browser, or how to get one; otherwise Chromium is launched headless on first use. */
|
|
5
5
|
browser?: Browser | (() => Promise<Browser>);
|
|
@@ -20,6 +20,15 @@ export interface PlaywrightRendererOptions {
|
|
|
20
20
|
* request's own `bundle` — set by the reader for a bundle URL — is routed the same way.
|
|
21
21
|
*/
|
|
22
22
|
bundles?: LocalBundle[];
|
|
23
|
+
/**
|
|
24
|
+
* The reader's pinned fetch (`@owlmeans/file-streams/fetch`): every live GET/HEAD the page makes that
|
|
25
|
+
* passes the guard is fetched through it (redirects come back to the browser, each hop guarded again)
|
|
26
|
+
* and fulfilled, instead of Chromium resolving the host again — the DNS-rebinding window between the
|
|
27
|
+
* guard and the connect. Other methods are refused. A render request's own `fetch` wins.
|
|
28
|
+
*/
|
|
29
|
+
fetch?: FetchFunction;
|
|
30
|
+
/** Bytes of one sub-request answer fulfilled through `fetch`; a larger one is aborted. Default 16 MiB. */
|
|
31
|
+
maxFulfilBytes?: number;
|
|
23
32
|
}
|
|
24
33
|
/** A {@link PageRenderer} on Playwright; `close` shuts down a browser it launched itself. */
|
|
25
34
|
export interface PlaywrightRenderer extends PageRenderer {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/renderer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/renderer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAE9H,MAAM,WAAW,yBAAyB;IACxC,iGAAiG;IACjG,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5C,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,aAAa,GAAG,QAAQ,CAAA;IAClE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IACvB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,0GAA0G;IAC1G,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,6FAA6F;AAC7F,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED,sCAAsC;AACtC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5C;AAED,MAAM,WAAW,4BAA4B;IAC3C,4EAA4E;IAC5E,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAA;CAC1C"}
|
package/build/renderer.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type { PlaywrightRenderer, PlaywrightRendererOptions } from './renderer/t
|
|
|
5
5
|
* challenges with a 407 so Chromium sends the route credentials), every request it makes is put
|
|
6
6
|
* through the reader's address guard, downloads are off and service workers blocked. A page of a
|
|
7
7
|
* local bundle (`bundles`, or the request's own `bundle`) is served from disk under its synthetic
|
|
8
|
-
* origin, while everything it loads from elsewhere still passes the guard.
|
|
8
|
+
* origin, while everything it loads from elsewhere still passes the guard. Given the reader's pinned
|
|
9
|
+
* `fetch`, every guarded live request is fetched through it and fulfilled, never re-resolved by Chromium.
|
|
9
10
|
*/
|
|
10
11
|
export declare const createPlaywrightRenderer: (options?: PlaywrightRendererOptions) => PlaywrightRenderer;
|
|
11
12
|
//# sourceMappingURL=renderer.d.ts.map
|
package/build/renderer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAIxF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,aAAa,yBAAyB,KAAQ,kBAwIlF,CAAA"}
|
package/build/renderer.js
CHANGED
|
@@ -1,15 +1,66 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '@owlmeans/log';
|
|
2
|
+
import { DEFAULT_MAX_FULFIL_BYTES, DEFAULT_RENDER_TIMEOUT_MS, DEFAULT_SETTLE_MS, DEFAULT_VIEWPORT, PROBE_ELEMENTS, SCREENSHOT_QUALITY, } from './consts.js';
|
|
3
|
+
import { FULFIL_DROPPED_HEADERS, FULFIL_REQUEST_HEADERS } from './renderer/consts.local.js';
|
|
2
4
|
import { probePage } from './renderer/probe.js';
|
|
5
|
+
import { inlineCssom } from './renderer/snapshot.js';
|
|
6
|
+
const log = logger('llm-reader-playwright');
|
|
3
7
|
/**
|
|
4
8
|
* Render pages in Chromium (or the browser you pass). Each page gets its own browser context:
|
|
5
9
|
* its proxy is the reader's lease (`endpoint()` — the upstream, or the SOCKS bridge, which
|
|
6
10
|
* challenges with a 407 so Chromium sends the route credentials), every request it makes is put
|
|
7
11
|
* through the reader's address guard, downloads are off and service workers blocked. A page of a
|
|
8
12
|
* local bundle (`bundles`, or the request's own `bundle`) is served from disk under its synthetic
|
|
9
|
-
* origin, while everything it loads from elsewhere still passes the guard.
|
|
13
|
+
* origin, while everything it loads from elsewhere still passes the guard. Given the reader's pinned
|
|
14
|
+
* `fetch`, every guarded live request is fetched through it and fulfilled, never re-resolved by Chromium.
|
|
10
15
|
*/
|
|
11
16
|
export const createPlaywrightRenderer = (options = {}) => {
|
|
12
17
|
let launched;
|
|
18
|
+
const maxFulfilBytes = options.maxFulfilBytes ?? DEFAULT_MAX_FULFIL_BYTES;
|
|
19
|
+
/** A body read whole under the cap — `route.fulfill` takes a buffer, not a stream. */
|
|
20
|
+
const bodyOf = async (response) => {
|
|
21
|
+
const declared = Number(response.headers.get('content-length') ?? NaN);
|
|
22
|
+
if (Number.isFinite(declared) && declared > maxFulfilBytes)
|
|
23
|
+
throw new Error(`too-large:${declared}`);
|
|
24
|
+
if (response.body == null)
|
|
25
|
+
return Buffer.alloc(0);
|
|
26
|
+
const chunks = [];
|
|
27
|
+
let size = 0;
|
|
28
|
+
const reader = response.body.getReader();
|
|
29
|
+
for (;;) {
|
|
30
|
+
const next = await reader.read();
|
|
31
|
+
if (next.done)
|
|
32
|
+
break;
|
|
33
|
+
size += next.value.byteLength;
|
|
34
|
+
if (size > maxFulfilBytes) {
|
|
35
|
+
await reader.cancel().catch(() => undefined);
|
|
36
|
+
throw new Error(`too-large:>${maxFulfilBytes}`);
|
|
37
|
+
}
|
|
38
|
+
chunks.push(next.value);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.concat(chunks);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A guarded sub-request carried by the injected fetch and fulfilled from its answer; redirects go
|
|
44
|
+
* back to the browser, whose next request passes the guard again.
|
|
45
|
+
*/
|
|
46
|
+
const fulfilThrough = async (fetch, route, signal) => {
|
|
47
|
+
const request = route.request();
|
|
48
|
+
const method = request.method().toUpperCase();
|
|
49
|
+
if (method !== 'GET' && method !== 'HEAD')
|
|
50
|
+
throw Object.assign(new Error(`method:${method}`), { refused: true });
|
|
51
|
+
const sent = request.headers();
|
|
52
|
+
const headers = Object.fromEntries(FULFIL_REQUEST_HEADERS.flatMap(name => sent[name] != null ? [[name, sent[name]]] : []));
|
|
53
|
+
const response = await fetch(request.url(), { method, headers, redirect: 'manual', ...(signal != null ? { signal } : {}) });
|
|
54
|
+
const answer = {};
|
|
55
|
+
response.headers.forEach((value, name) => {
|
|
56
|
+
if (!FULFIL_DROPPED_HEADERS.includes(name) && name !== 'set-cookie')
|
|
57
|
+
answer[name] = value;
|
|
58
|
+
});
|
|
59
|
+
const cookies = response.headers.getSetCookie?.() ?? [];
|
|
60
|
+
if (cookies.length > 0)
|
|
61
|
+
answer['set-cookie'] = cookies.join('\n');
|
|
62
|
+
await route.fulfill({ status: response.status, headers: answer, body: method === 'HEAD' ? Buffer.alloc(0) : await bodyOf(response) });
|
|
63
|
+
};
|
|
13
64
|
const browserOf = async () => {
|
|
14
65
|
if (options.browser != null) {
|
|
15
66
|
return typeof options.browser === 'function' ? options.browser() : options.browser;
|
|
@@ -31,8 +82,10 @@ export const createPlaywrightRenderer = (options = {}) => {
|
|
|
31
82
|
});
|
|
32
83
|
const blocked = [];
|
|
33
84
|
const bundles = [...(options.bundles ?? []), ...(request.bundle != null ? [request.bundle] : [])];
|
|
85
|
+
// Through a lease the proxy carries the request; an injected fetch would bypass it.
|
|
86
|
+
const fetch = endpoint == null ? request.fetch ?? options.fetch : undefined;
|
|
34
87
|
try {
|
|
35
|
-
if (request.guard != null || bundles.length > 0) {
|
|
88
|
+
if (request.guard != null || bundles.length > 0 || fetch != null) {
|
|
36
89
|
const guard = request.guard;
|
|
37
90
|
await context.route('**/*', async (route) => {
|
|
38
91
|
const url = route.request().url();
|
|
@@ -49,11 +102,23 @@ export const createPlaywrightRenderer = (options = {}) => {
|
|
|
49
102
|
return;
|
|
50
103
|
}
|
|
51
104
|
await guard?.check(url, endpoint == null);
|
|
52
|
-
await route.continue();
|
|
53
105
|
}
|
|
54
106
|
catch {
|
|
55
107
|
blocked.push(url);
|
|
56
108
|
await route.abort('blockedbyclient');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (fetch == null)
|
|
112
|
+
return route.continue();
|
|
113
|
+
try {
|
|
114
|
+
await fulfilThrough(fetch, route, request.signal);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
const refused = e?.refused === true;
|
|
118
|
+
if (refused)
|
|
119
|
+
blocked.push(url);
|
|
120
|
+
log.debug('Sub-request not fulfilled', { host: new URL(url).host, refused, error: e });
|
|
121
|
+
await route.abort(refused ? 'blockedbyclient' : 'failed').catch(() => undefined);
|
|
57
122
|
}
|
|
58
123
|
});
|
|
59
124
|
}
|
|
@@ -64,6 +129,8 @@ export const createPlaywrightRenderer = (options = {}) => {
|
|
|
64
129
|
});
|
|
65
130
|
await page.waitForLoadState('networkidle', { timeout: options.settle ?? DEFAULT_SETTLE_MS }).catch(() => undefined);
|
|
66
131
|
const probe = request.styles === true ? await page.evaluate(probePage, PROBE_ELEMENTS) : undefined;
|
|
132
|
+
if (request.snapshot === true)
|
|
133
|
+
await page.evaluate(inlineCssom);
|
|
67
134
|
const screenshot = request.screenshot === true
|
|
68
135
|
? new Uint8Array(await page.screenshot({ type: 'jpeg', quality: SCREENSHOT_QUALITY }))
|
|
69
136
|
: undefined;
|
package/build/renderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EACL,wBAAwB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,GAC7H,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGpD,MAAM,GAAG,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAA;AAE3C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAO,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ACT,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC,CAAA;IAED,MAAM,KAAK,GAAG,KAAK,IAAmB,EAAE;QACtC,MAAM,OAAO,GAAG,QAAQ,CAAA;QACxB,QAAQ,GAAG,SAAS,CAAA;QACpB,IAAI,OAAO,IAAI,IAAI;YAAE,MAAM,CAAC,MAAM,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;IACpD,CAAC,CAAA;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;AAC1B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/llm-reader-playwright",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Playwright renderer for @owlmeans/llm-reader: script-run pages, computed styles, screenshots, offline bundles and guarded sub-requests.",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"homepage": "https://owlmeans.com/docs/",
|
|
6
7
|
"repository": {
|
|
@@ -32,14 +33,14 @@
|
|
|
32
33
|
}
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@owlmeans/error": "^0.
|
|
36
|
-
"@owlmeans/llm-reader": "^0.
|
|
37
|
-
"@owlmeans/log": "^0.
|
|
36
|
+
"@owlmeans/error": "^0.2.0",
|
|
37
|
+
"@owlmeans/llm-reader": "^0.2.0",
|
|
38
|
+
"@owlmeans/log": "^0.2.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@owlmeans/dep-config": "^0.
|
|
41
|
-
"@owlmeans/test": "^0.
|
|
42
|
-
"@owlmeans/test-ui": "^0.
|
|
41
|
+
"@owlmeans/dep-config": "^0.2.0",
|
|
42
|
+
"@owlmeans/test": "^0.2.0",
|
|
43
|
+
"@owlmeans/test-ui": "^0.2.0",
|
|
43
44
|
"@types/bun": "^1.4.4",
|
|
44
45
|
"@types/node": "^26.6.5",
|
|
45
46
|
"nodemon": "^3.1.14",
|
package/src/consts.ts
CHANGED
|
@@ -12,3 +12,6 @@ export const SCREENSHOT_QUALITY = 70
|
|
|
12
12
|
|
|
13
13
|
/** Elements the style probe samples, at most. */
|
|
14
14
|
export const PROBE_ELEMENTS = 4000
|
|
15
|
+
|
|
16
|
+
/** Bytes of one sub-request answer fulfilled through an injected fetch. */
|
|
17
|
+
export const DEFAULT_MAX_FULFIL_BYTES = 16 * 1024 * 1024
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Request headers a page's sub-request carries into an injected fetch. */
|
|
2
|
+
export const FULFIL_REQUEST_HEADERS: readonly string[] = Object.freeze([
|
|
3
|
+
'accept', 'accept-language', 'user-agent', 'referer', 'range', 'if-none-match', 'if-modified-since', 'cache-control',
|
|
4
|
+
])
|
|
5
|
+
|
|
6
|
+
/** Response headers never handed back to the browser: the body is decoded and whole. */
|
|
7
|
+
export const FULFIL_DROPPED_HEADERS: readonly string[] = Object.freeze([
|
|
8
|
+
'content-encoding', 'content-length', 'transfer-encoding', 'connection', 'keep-alive',
|
|
9
|
+
])
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs INSIDE the rendered page (serialized by Playwright — it may use nothing from this module's
|
|
3
|
+
* scope). Writes the rules a script put only into the CSSOM — `insertRule` on a `<style>` (CSS-in-JS)
|
|
4
|
+
* and adopted stylesheets — into `<style>` elements, so the serialized DOM keeps its look without the
|
|
5
|
+
* scripts. Answers how many rules it wrote.
|
|
6
|
+
*/
|
|
7
|
+
export const inlineCssom = (): number => {
|
|
8
|
+
let written = 0
|
|
9
|
+
const textOf = (sheet: CSSStyleSheet): string | undefined => {
|
|
10
|
+
try {
|
|
11
|
+
return Array.from(sheet.cssRules).map(rule => rule.cssText).join('\n')
|
|
12
|
+
} catch {
|
|
13
|
+
return undefined // a cross-origin sheet keeps its own link
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
17
|
+
const owner = sheet.ownerNode
|
|
18
|
+
if (!(owner instanceof HTMLStyleElement)) continue
|
|
19
|
+
const text = textOf(sheet)
|
|
20
|
+
if (text == null || sheet.cssRules.length === 0) continue
|
|
21
|
+
// A `<style>` whose text already holds every rule is left as written.
|
|
22
|
+
const parsed = new CSSStyleSheet()
|
|
23
|
+
try {
|
|
24
|
+
parsed.replaceSync(owner.textContent ?? '')
|
|
25
|
+
} catch {
|
|
26
|
+
// unparseable text: its rules are whatever the CSSOM holds
|
|
27
|
+
}
|
|
28
|
+
if (parsed.cssRules.length === sheet.cssRules.length) continue
|
|
29
|
+
owner.textContent = text
|
|
30
|
+
written += sheet.cssRules.length
|
|
31
|
+
}
|
|
32
|
+
const adopted = (document as Document & { adoptedStyleSheets?: CSSStyleSheet[] }).adoptedStyleSheets ?? []
|
|
33
|
+
for (const sheet of adopted) {
|
|
34
|
+
const text = textOf(sheet)
|
|
35
|
+
if (text == null || text === '') continue
|
|
36
|
+
const style = document.createElement('style')
|
|
37
|
+
style.setAttribute('data-owlmeans-adopted', '')
|
|
38
|
+
style.textContent = text
|
|
39
|
+
document.head.appendChild(style)
|
|
40
|
+
written += sheet.cssRules.length
|
|
41
|
+
}
|
|
42
|
+
return written
|
|
43
|
+
}
|
package/src/renderer/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Browser, LaunchOptions } from 'playwright'
|
|
2
|
-
import type { FetchRequest, LocalBundle, PageRenderer, RenderedBlock, StyleSample } from '@owlmeans/llm-reader'
|
|
2
|
+
import type { FetchFunction, FetchRequest, LocalBundle, PageRenderer, RenderedBlock, StyleSample } from '@owlmeans/llm-reader'
|
|
3
3
|
|
|
4
4
|
export interface PlaywrightRendererOptions {
|
|
5
5
|
/** Your own browser, or how to get one; otherwise Chromium is launched headless on first use. */
|
|
@@ -18,6 +18,15 @@ export interface PlaywrightRendererOptions {
|
|
|
18
18
|
* request's own `bundle` — set by the reader for a bundle URL — is routed the same way.
|
|
19
19
|
*/
|
|
20
20
|
bundles?: LocalBundle[]
|
|
21
|
+
/**
|
|
22
|
+
* The reader's pinned fetch (`@owlmeans/file-streams/fetch`): every live GET/HEAD the page makes that
|
|
23
|
+
* passes the guard is fetched through it (redirects come back to the browser, each hop guarded again)
|
|
24
|
+
* and fulfilled, instead of Chromium resolving the host again — the DNS-rebinding window between the
|
|
25
|
+
* guard and the connect. Other methods are refused. A render request's own `fetch` wins.
|
|
26
|
+
*/
|
|
27
|
+
fetch?: FetchFunction
|
|
28
|
+
/** Bytes of one sub-request answer fulfilled through `fetch`; a larger one is aborted. Default 16 MiB. */
|
|
29
|
+
maxFulfilBytes?: number
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
/** A {@link PageRenderer} on Playwright; `close` shuts down a browser it launched itself. */
|
package/src/renderer.ts
CHANGED
|
@@ -1,19 +1,69 @@
|
|
|
1
|
-
import type { Browser, BrowserContext } from 'playwright'
|
|
2
|
-
import type { RenderedPage } from '@owlmeans/llm-reader'
|
|
3
|
-
import {
|
|
1
|
+
import type { Browser, BrowserContext, Route } from 'playwright'
|
|
2
|
+
import type { FetchFunction, RenderedPage } from '@owlmeans/llm-reader'
|
|
3
|
+
import { logger } from '@owlmeans/log'
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_MAX_FULFIL_BYTES, DEFAULT_RENDER_TIMEOUT_MS, DEFAULT_SETTLE_MS, DEFAULT_VIEWPORT, PROBE_ELEMENTS, SCREENSHOT_QUALITY,
|
|
6
|
+
} from './consts.js'
|
|
7
|
+
import { FULFIL_DROPPED_HEADERS, FULFIL_REQUEST_HEADERS } from './renderer/consts.local.js'
|
|
4
8
|
import { probePage } from './renderer/probe.js'
|
|
9
|
+
import { inlineCssom } from './renderer/snapshot.js'
|
|
5
10
|
import type { PlaywrightRenderer, PlaywrightRendererOptions } from './renderer/types.js'
|
|
6
11
|
|
|
12
|
+
const log = logger('llm-reader-playwright')
|
|
13
|
+
|
|
7
14
|
/**
|
|
8
15
|
* Render pages in Chromium (or the browser you pass). Each page gets its own browser context:
|
|
9
16
|
* its proxy is the reader's lease (`endpoint()` — the upstream, or the SOCKS bridge, which
|
|
10
17
|
* challenges with a 407 so Chromium sends the route credentials), every request it makes is put
|
|
11
18
|
* through the reader's address guard, downloads are off and service workers blocked. A page of a
|
|
12
19
|
* local bundle (`bundles`, or the request's own `bundle`) is served from disk under its synthetic
|
|
13
|
-
* origin, while everything it loads from elsewhere still passes the guard.
|
|
20
|
+
* origin, while everything it loads from elsewhere still passes the guard. Given the reader's pinned
|
|
21
|
+
* `fetch`, every guarded live request is fetched through it and fulfilled, never re-resolved by Chromium.
|
|
14
22
|
*/
|
|
15
23
|
export const createPlaywrightRenderer = (options: PlaywrightRendererOptions = {}): PlaywrightRenderer => {
|
|
16
24
|
let launched: Promise<Browser> | undefined
|
|
25
|
+
const maxFulfilBytes = options.maxFulfilBytes ?? DEFAULT_MAX_FULFIL_BYTES
|
|
26
|
+
|
|
27
|
+
/** A body read whole under the cap — `route.fulfill` takes a buffer, not a stream. */
|
|
28
|
+
const bodyOf = async (response: Response): Promise<Buffer> => {
|
|
29
|
+
const declared = Number(response.headers.get('content-length') ?? NaN)
|
|
30
|
+
if (Number.isFinite(declared) && declared > maxFulfilBytes) throw new Error(`too-large:${declared}`)
|
|
31
|
+
if (response.body == null) return Buffer.alloc(0)
|
|
32
|
+
const chunks: Uint8Array[] = []
|
|
33
|
+
let size = 0
|
|
34
|
+
const reader = response.body.getReader()
|
|
35
|
+
for (;;) {
|
|
36
|
+
const next = await reader.read()
|
|
37
|
+
if (next.done) break
|
|
38
|
+
size += next.value.byteLength
|
|
39
|
+
if (size > maxFulfilBytes) {
|
|
40
|
+
await reader.cancel().catch(() => undefined)
|
|
41
|
+
throw new Error(`too-large:>${maxFulfilBytes}`)
|
|
42
|
+
}
|
|
43
|
+
chunks.push(next.value)
|
|
44
|
+
}
|
|
45
|
+
return Buffer.concat(chunks)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A guarded sub-request carried by the injected fetch and fulfilled from its answer; redirects go
|
|
50
|
+
* back to the browser, whose next request passes the guard again.
|
|
51
|
+
*/
|
|
52
|
+
const fulfilThrough = async (fetch: FetchFunction, route: Route, signal?: AbortSignal): Promise<void> => {
|
|
53
|
+
const request = route.request()
|
|
54
|
+
const method = request.method().toUpperCase()
|
|
55
|
+
if (method !== 'GET' && method !== 'HEAD') throw Object.assign(new Error(`method:${method}`), { refused: true })
|
|
56
|
+
const sent = request.headers()
|
|
57
|
+
const headers = Object.fromEntries(FULFIL_REQUEST_HEADERS.flatMap(name => sent[name] != null ? [[name, sent[name]!]] : []))
|
|
58
|
+
const response = await fetch(request.url(), { method, headers, redirect: 'manual', ...(signal != null ? { signal } : {}) })
|
|
59
|
+
const answer: Record<string, string> = {}
|
|
60
|
+
response.headers.forEach((value, name) => {
|
|
61
|
+
if (!FULFIL_DROPPED_HEADERS.includes(name) && name !== 'set-cookie') answer[name] = value
|
|
62
|
+
})
|
|
63
|
+
const cookies = response.headers.getSetCookie?.() ?? []
|
|
64
|
+
if (cookies.length > 0) answer['set-cookie'] = cookies.join('\n')
|
|
65
|
+
await route.fulfill({ status: response.status, headers: answer, body: method === 'HEAD' ? Buffer.alloc(0) : await bodyOf(response) })
|
|
66
|
+
}
|
|
17
67
|
|
|
18
68
|
const browserOf = async (): Promise<Browser> => {
|
|
19
69
|
if (options.browser != null) {
|
|
@@ -37,8 +87,10 @@ export const createPlaywrightRenderer = (options: PlaywrightRendererOptions = {}
|
|
|
37
87
|
})
|
|
38
88
|
const blocked: string[] = []
|
|
39
89
|
const bundles = [...(options.bundles ?? []), ...(request.bundle != null ? [request.bundle] : [])]
|
|
90
|
+
// Through a lease the proxy carries the request; an injected fetch would bypass it.
|
|
91
|
+
const fetch = endpoint == null ? request.fetch ?? options.fetch : undefined
|
|
40
92
|
try {
|
|
41
|
-
if (request.guard != null || bundles.length > 0) {
|
|
93
|
+
if (request.guard != null || bundles.length > 0 || fetch != null) {
|
|
42
94
|
const guard = request.guard
|
|
43
95
|
await context.route('**/*', async route => {
|
|
44
96
|
const url = route.request().url()
|
|
@@ -54,10 +106,19 @@ export const createPlaywrightRenderer = (options: PlaywrightRendererOptions = {}
|
|
|
54
106
|
return
|
|
55
107
|
}
|
|
56
108
|
await guard?.check(url, endpoint == null)
|
|
57
|
-
await route.continue()
|
|
58
109
|
} catch {
|
|
59
110
|
blocked.push(url)
|
|
60
111
|
await route.abort('blockedbyclient')
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
if (fetch == null) return route.continue()
|
|
115
|
+
try {
|
|
116
|
+
await fulfilThrough(fetch, route, request.signal)
|
|
117
|
+
} catch (e) {
|
|
118
|
+
const refused = (e as { refused?: unknown } | null)?.refused === true
|
|
119
|
+
if (refused) blocked.push(url)
|
|
120
|
+
log.debug('Sub-request not fulfilled', { host: new URL(url).host, refused, error: e })
|
|
121
|
+
await route.abort(refused ? 'blockedbyclient' : 'failed').catch(() => undefined)
|
|
61
122
|
}
|
|
62
123
|
})
|
|
63
124
|
}
|
|
@@ -68,6 +129,7 @@ export const createPlaywrightRenderer = (options: PlaywrightRendererOptions = {}
|
|
|
68
129
|
})
|
|
69
130
|
await page.waitForLoadState('networkidle', { timeout: options.settle ?? DEFAULT_SETTLE_MS }).catch(() => undefined)
|
|
70
131
|
const probe = request.styles === true ? await page.evaluate(probePage, PROBE_ELEMENTS) : undefined
|
|
132
|
+
if (request.snapshot === true) await page.evaluate(inlineCssom)
|
|
71
133
|
const screenshot = request.screenshot === true
|
|
72
134
|
? new Uint8Array(await page.screenshot({ type: 'jpeg', quality: SCREENSHOT_QUALITY }))
|
|
73
135
|
: undefined
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from 'bun:test'
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { mkdtemp, readFile, rm } from 'node:fs/promises'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { chromium } from 'playwright'
|
|
7
|
+
import { createBrowserHelper } from '@owlmeans/test-ui'
|
|
8
|
+
import {
|
|
9
|
+
BUNDLE_MANIFEST, CollectKind, createAddressGuard, createDirectoryCollectSink, createLlmReader, createLocalBundlePlugin,
|
|
10
|
+
} from '@owlmeans/llm-reader'
|
|
11
|
+
import type { BundleManifest } from '@owlmeans/llm-reader'
|
|
12
|
+
import { createPlaywrightRenderer } from '../src/index.js'
|
|
13
|
+
// The reader's own fixture servers, and the pinned fetch a consumer injects (test-only reach into file-streams).
|
|
14
|
+
import { startCdn, startCollectSite } from '../../llm-reader/tests/servers.js'
|
|
15
|
+
import { createPinnedFetch } from '../../file-streams/src/fetch.js'
|
|
16
|
+
|
|
17
|
+
const skip = existsSync(chromium.executablePath()) ? null : `no Chromium at ${chromium.executablePath()}`
|
|
18
|
+
const titled = (name: string, reason: string | null) => reason != null ? `${name} — SKIPPED: ${reason}` : name
|
|
19
|
+
|
|
20
|
+
const browsers = createBrowserHelper()
|
|
21
|
+
const browser = () => browsers.launchBrowser()
|
|
22
|
+
const scratch = await mkdtemp(join(tmpdir(), 'llm-reader-playwright-collect-'))
|
|
23
|
+
afterAll(async () => {
|
|
24
|
+
await browsers.closeBrowser()
|
|
25
|
+
await rm(scratch, { recursive: true, force: true })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('@owlmeans/llm-reader-playwright — collected bundles and the pinned fetch', () => {
|
|
29
|
+
test.skipIf(skip != null)(titled('a collected bundle renders offline: imported stylesheets, the external web font, no live network', skip), async () => {
|
|
30
|
+
const cdn = startCdn()
|
|
31
|
+
const site = startCollectSite(cdn.url)
|
|
32
|
+
const root = join(scratch, 'offline')
|
|
33
|
+
await createLlmReader({ allowHosts: ['127.0.0.1'] }).collect(`${site.url}/`, { sink: createDirectoryCollectSink(root) })
|
|
34
|
+
site.stop()
|
|
35
|
+
cdn.stop()
|
|
36
|
+
|
|
37
|
+
const bundle = createLocalBundlePlugin({ root })
|
|
38
|
+
const guard = createAddressGuard({ allowHosts: ['127.0.0.1'] })
|
|
39
|
+
const page = await createPlaywrightRenderer({ browser, bundles: [bundle] }).render({ url: bundle.urlOf('index.html'), guard, styles: true })
|
|
40
|
+
expect(page.status).toBe(200)
|
|
41
|
+
expect(page.html).toContain('Collected page')
|
|
42
|
+
const h1 = page.styles!.find(sample => sample.role === 'heading-1')!
|
|
43
|
+
expect(h1.color).toBe('rgb(10, 20, 30)') // from print.css, @imported by site.css
|
|
44
|
+
expect(page.styles!.find(sample => sample.role === 'body')!.fontFamily).toContain('Inter') // the CDN's stylesheet
|
|
45
|
+
// Only the address the bundle left absolute because the guard refused it was tried, and refused again.
|
|
46
|
+
expect(page.blocked).toEqual(['http://169.254.169.254/latest/meta-data/logo.png'])
|
|
47
|
+
|
|
48
|
+
// The original URL renders from disk too, through the reader — its servers are gone.
|
|
49
|
+
const offline = createLlmReader({ renderer: createPlaywrightRenderer({ browser }), plugins: [bundle], allowHosts: ['127.0.0.1'] })
|
|
50
|
+
const original = await offline.page(`${site.url}/`, { render: true })
|
|
51
|
+
expect(original.rendered?.html).toContain('Collected page')
|
|
52
|
+
expect(original.rendered?.styles?.find(sample => sample.role === 'heading-1')?.color).toBe('rgb(10, 20, 30)')
|
|
53
|
+
}, 90_000)
|
|
54
|
+
|
|
55
|
+
test.skipIf(skip != null)(titled('an app shell is collected as its rendered snapshot: CSSOM rules inlined, scripts gone', skip), async () => {
|
|
56
|
+
const cdn = startCdn()
|
|
57
|
+
const site = startCollectSite(cdn.url)
|
|
58
|
+
try {
|
|
59
|
+
const root = join(scratch, 'shell')
|
|
60
|
+
const reader = createLlmReader({ renderer: createPlaywrightRenderer({ browser }), allowHosts: ['127.0.0.1'] })
|
|
61
|
+
const result = await reader.collect(`${site.url}/shell`, { sink: createDirectoryCollectSink(root) })
|
|
62
|
+
expect(result).toMatchObject({ kind: CollectKind.Bundle, entry: 'shell.html' })
|
|
63
|
+
const html = await readFile(join(root, 'shell.html'), 'utf8')
|
|
64
|
+
expect(html).toContain('Rendered by script')
|
|
65
|
+
expect(html).not.toContain('<script')
|
|
66
|
+
expect(html).toMatch(/<style>[^<]*\.shell-title\s*\{[^}]*color: rgb\(200, 30, 30\)/)
|
|
67
|
+
expect(html).toContain('src="img/logo.png"')
|
|
68
|
+
const manifest = JSON.parse(await readFile(join(root, BUNDLE_MANIFEST), 'utf8')) as BundleManifest
|
|
69
|
+
expect(manifest.rendered).toBe(true)
|
|
70
|
+
expect(manifest.files[`${site.url}/img/logo.png`]).toBe('img/logo.png')
|
|
71
|
+
} finally {
|
|
72
|
+
site.stop()
|
|
73
|
+
cdn.stop()
|
|
74
|
+
}
|
|
75
|
+
}, 90_000)
|
|
76
|
+
|
|
77
|
+
test.skipIf(skip != null)(titled('with an injected fetch, guarded sub-requests are fulfilled through it — its pinning refuses what Chromium would load', skip), async () => {
|
|
78
|
+
const cdn = startCdn('127.0.0.2')
|
|
79
|
+
const site = startCollectSite(cdn.url)
|
|
80
|
+
try {
|
|
81
|
+
const fetch = createPinnedFetch({ network: { allowCidrs: ['127.0.0.1/32'] }, resolvers: [], timeouts: { connectMs: 3000, headersMs: 3000, idleMs: 3000 } })
|
|
82
|
+
const guard = createAddressGuard({ allowHosts: ['127.0.0.1', '127.0.0.2'] })
|
|
83
|
+
const page = await createPlaywrightRenderer({ browser, fetch }).render({ url: `${site.url}/`, guard, styles: true })
|
|
84
|
+
expect(page.status).toBe(200)
|
|
85
|
+
expect(page.styles!.find(sample => sample.role === 'heading-1')!.color).toBe('rgb(10, 20, 30)')
|
|
86
|
+
// The guard let the CDN through; the pinned connect refused it.
|
|
87
|
+
expect(page.blocked?.some(url => url.startsWith(cdn.url))).toBe(true)
|
|
88
|
+
expect(cdn.hits).toEqual([])
|
|
89
|
+
expect(site.hits).toContain('/css/print.css')
|
|
90
|
+
|
|
91
|
+
// A fulfilled redirect goes back to Chromium, whose next request is routed (and guarded) again.
|
|
92
|
+
const moved = await createPlaywrightRenderer({ browser, fetch }).render({ url: `${site.url}/moved`, guard })
|
|
93
|
+
expect(moved.finalUrl).toBe(`${site.url}/docs/`)
|
|
94
|
+
expect(moved.html).toContain('Docs home')
|
|
95
|
+
} finally {
|
|
96
|
+
site.stop()
|
|
97
|
+
cdn.stop()
|
|
98
|
+
}
|
|
99
|
+
}, 90_000)
|
|
100
|
+
})
|