rasterport 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -1
- package/dist/capture.js +5 -1
- package/dist/capture.js.map +1 -1
- package/dist/cli.js +29 -0
- package/dist/cli.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/llms.txt +147 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# rasterport
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Capture web screenshots + DOM in one command. Built for AI agents, CI, and automation.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npx rasterport https://example.com
|
|
@@ -16,12 +16,22 @@ rasterport <url> [options]
|
|
|
16
16
|
--height <number> Browser height (default: 800)
|
|
17
17
|
--format <base64|buffer>
|
|
18
18
|
Screenshot output format (default: base64)
|
|
19
|
+
--image-format <png|jpeg>
|
|
20
|
+
Screenshot image format (default: jpeg)
|
|
21
|
+
--quality <number> JPEG quality from 1-100 (default: 70)
|
|
19
22
|
--out <file> Write JSON to a file instead of stdout
|
|
20
23
|
--screenshot-only Return only the screenshot
|
|
21
24
|
--dom-only Return only the DOM
|
|
22
25
|
--help Show help
|
|
23
26
|
```
|
|
24
27
|
|
|
28
|
+
JPEG is the default because it keeps screenshot payloads much smaller while
|
|
29
|
+
remaining readable for agent workflows. Use PNG when you need lossless output:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
rasterport https://example.com --screenshot-only --image-format png
|
|
33
|
+
```
|
|
34
|
+
|
|
25
35
|
The default output is JSON:
|
|
26
36
|
|
|
27
37
|
```json
|
|
@@ -35,3 +45,40 @@ The default output is JSON:
|
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
```
|
|
48
|
+
|
|
49
|
+
## Why rasterport?
|
|
50
|
+
|
|
51
|
+
- Single CLI command for screenshot + DOM capture
|
|
52
|
+
- JPEG screenshots by default to keep payloads smaller
|
|
53
|
+
- Returns screenshot and DOM together
|
|
54
|
+
- Designed for AI agents and automation workflows
|
|
55
|
+
- Works well in CI pipelines
|
|
56
|
+
|
|
57
|
+
## rasterport vs Puppeteer
|
|
58
|
+
|
|
59
|
+
| Feature | rasterport | Puppeteer |
|
|
60
|
+
|-----------------|------------|-----------|
|
|
61
|
+
| Setup | zero | heavy |
|
|
62
|
+
| Output size | small | large |
|
|
63
|
+
| API | simple | complex |
|
|
64
|
+
| Agent workflows | native | manual |
|
|
65
|
+
|
|
66
|
+
## For AI agents
|
|
67
|
+
|
|
68
|
+
rasterport exports the same `capture` function used by the CLI:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { capture } from "rasterport";
|
|
72
|
+
|
|
73
|
+
await capture({
|
|
74
|
+
url: task.url,
|
|
75
|
+
fullPage: false,
|
|
76
|
+
width: 1280,
|
|
77
|
+
height: 800,
|
|
78
|
+
format: "base64",
|
|
79
|
+
imageFormat: "jpeg",
|
|
80
|
+
quality: 70,
|
|
81
|
+
screenshotOnly: true,
|
|
82
|
+
domOnly: false,
|
|
83
|
+
});
|
|
84
|
+
```
|
package/dist/capture.js
CHANGED
|
@@ -4,7 +4,11 @@ export async function capture(options) {
|
|
|
4
4
|
await page.goto(options.url, { waitUntil: "networkidle" });
|
|
5
5
|
const screenshot = options.domOnly
|
|
6
6
|
? undefined
|
|
7
|
-
: await page.screenshot({
|
|
7
|
+
: await page.screenshot({
|
|
8
|
+
fullPage: options.fullPage,
|
|
9
|
+
type: options.imageFormat,
|
|
10
|
+
quality: options.imageFormat === "jpeg" ? options.quality : undefined,
|
|
11
|
+
});
|
|
8
12
|
const dom = options.screenshotOnly ? undefined : await page.content();
|
|
9
13
|
return {
|
|
10
14
|
screenshot: serializeScreenshot(screenshot, options.format),
|
package/dist/capture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAA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C,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAEtE,OAAO;YACL,UAAU,EAAE,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC;YAC3D,GAAG;YACH,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;YACf,QAAQ,EAAE;gBACR,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAC1B,UAA8B,EAC9B,MAA4B;IAE5B,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,KAAK,QAAQ;QACxB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;QACxB,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,8 @@ import { capture } from "./capture.js";
|
|
|
3
3
|
import { outputResult } from "./serializer.js";
|
|
4
4
|
const DEFAULT_WIDTH = 1280;
|
|
5
5
|
const DEFAULT_HEIGHT = 800;
|
|
6
|
+
const DEFAULT_IMAGE_FORMAT = "jpeg";
|
|
7
|
+
const DEFAULT_QUALITY = 70;
|
|
6
8
|
async function main() {
|
|
7
9
|
const options = parseArgs(process.argv.slice(2));
|
|
8
10
|
const result = await capture(options);
|
|
@@ -23,6 +25,8 @@ function parseArgs(args) {
|
|
|
23
25
|
width: DEFAULT_WIDTH,
|
|
24
26
|
height: DEFAULT_HEIGHT,
|
|
25
27
|
format: "base64",
|
|
28
|
+
imageFormat: DEFAULT_IMAGE_FORMAT,
|
|
29
|
+
quality: DEFAULT_QUALITY,
|
|
26
30
|
screenshotOnly: false,
|
|
27
31
|
domOnly: false,
|
|
28
32
|
};
|
|
@@ -41,6 +45,12 @@ function parseArgs(args) {
|
|
|
41
45
|
case "--format":
|
|
42
46
|
options.format = parseFormat(readValue(args, ++index, arg));
|
|
43
47
|
break;
|
|
48
|
+
case "--image-format":
|
|
49
|
+
options.imageFormat = parseImageFormat(readValue(args, ++index, arg));
|
|
50
|
+
break;
|
|
51
|
+
case "--quality":
|
|
52
|
+
options.quality = parseQuality(readValue(args, ++index, arg), arg);
|
|
53
|
+
break;
|
|
44
54
|
case "--out":
|
|
45
55
|
options.out = readValue(args, ++index, arg);
|
|
46
56
|
break;
|
|
@@ -57,6 +67,9 @@ function parseArgs(args) {
|
|
|
57
67
|
if (options.screenshotOnly && options.domOnly) {
|
|
58
68
|
throw new Error("Use either --screenshot-only or --dom-only, not both.");
|
|
59
69
|
}
|
|
70
|
+
if (options.quality && options.imageFormat !== "jpeg") {
|
|
71
|
+
throw new Error("--quality can only be used with --image-format jpeg.");
|
|
72
|
+
}
|
|
60
73
|
return options;
|
|
61
74
|
}
|
|
62
75
|
function readValue(args, index, option) {
|
|
@@ -79,6 +92,19 @@ function parseFormat(value) {
|
|
|
79
92
|
}
|
|
80
93
|
throw new Error("--format must be either base64 or buffer");
|
|
81
94
|
}
|
|
95
|
+
function parseImageFormat(value) {
|
|
96
|
+
if (value === "png" || value === "jpeg") {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
throw new Error("--image-format must be either png or jpeg");
|
|
100
|
+
}
|
|
101
|
+
function parseQuality(value, option) {
|
|
102
|
+
const number = parsePositiveNumber(value, option);
|
|
103
|
+
if (number > 100) {
|
|
104
|
+
throw new Error(`${option} must be between 1 and 100`);
|
|
105
|
+
}
|
|
106
|
+
return number;
|
|
107
|
+
}
|
|
82
108
|
function printHelp() {
|
|
83
109
|
process.stdout.write(`rasterport <url> [options]
|
|
84
110
|
|
|
@@ -88,6 +114,9 @@ Options:
|
|
|
88
114
|
--height <number> Browser height (default: ${DEFAULT_HEIGHT})
|
|
89
115
|
--format <base64|buffer>
|
|
90
116
|
Screenshot output format (default: base64)
|
|
117
|
+
--image-format <png|jpeg>
|
|
118
|
+
Screenshot image format (default: ${DEFAULT_IMAGE_FORMAT})
|
|
119
|
+
--quality <number> JPEG quality from 1-100 (default: ${DEFAULT_QUALITY})
|
|
91
120
|
--out <file> Write JSON to a file instead of stdout
|
|
92
121
|
--screenshot-only Return only the screenshot
|
|
93
122
|
--dom-only Return only the DOM
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAO/C,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,KAAK,UAAU,IAAI;IACjB,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACxE,SAAS,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,M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AAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,OAAO,IAAI,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export type ScreenshotFormat = "base64" | "buffer";
|
|
2
|
+
export type ScreenshotImageFormat = "png" | "jpeg";
|
|
2
3
|
export interface CliOptions {
|
|
3
4
|
url: string;
|
|
4
5
|
fullPage: boolean;
|
|
5
6
|
width: number;
|
|
6
7
|
height: number;
|
|
7
8
|
format: ScreenshotFormat;
|
|
9
|
+
imageFormat: ScreenshotImageFormat;
|
|
10
|
+
quality?: number;
|
|
8
11
|
out?: string;
|
|
9
12
|
screenshotOnly: boolean;
|
|
10
13
|
domOnly: boolean;
|
package/llms.txt
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Rasterport
|
|
2
|
+
|
|
3
|
+
Rasterport is a small CLI for capturing web pages as JSON for AI agent and LLM
|
|
4
|
+
workflows. It uses Playwright to load a page, then returns a screenshot, the
|
|
5
|
+
rendered DOM, the final URL, and viewport metadata.
|
|
6
|
+
|
|
7
|
+
Use Rasterport when an agent needs visual grounding for a URL, DOM context for
|
|
8
|
+
text and structure, or both.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Use the published package with npx:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx rasterport https://example.com
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or install it globally:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g rasterport
|
|
22
|
+
rasterport https://example.com
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Default Output
|
|
26
|
+
|
|
27
|
+
By default, Rasterport returns JSON with:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"screenshot": "<base64-encoded image>",
|
|
32
|
+
"dom": "<rendered html>",
|
|
33
|
+
"url": "https://example.com/",
|
|
34
|
+
"viewport": {
|
|
35
|
+
"width": 1280,
|
|
36
|
+
"height": 800
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The default screenshot image format is JPEG at quality 70. This keeps payloads
|
|
42
|
+
much smaller than PNG while remaining readable for vision-capable agents.
|
|
43
|
+
|
|
44
|
+
## Recommended Agent Commands
|
|
45
|
+
|
|
46
|
+
For most AI-agent page understanding:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
rasterport https://example.com --out page.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This gives the agent both visual context and rendered DOM context.
|
|
53
|
+
|
|
54
|
+
For vision-only inspection with a smaller payload:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
rasterport https://example.com --screenshot-only --out screenshot.json
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
For text and structure only:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
rasterport https://example.com --dom-only --out dom.json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For pages where important content is below the fold:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
rasterport https://example.com --full-page --out page.json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
For mobile-ish rendering:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
rasterport https://example.com --width 390 --height 844 --out mobile.json
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Output Size Guidance
|
|
79
|
+
|
|
80
|
+
Rasterport is designed for agent workflows where payload size matters.
|
|
81
|
+
|
|
82
|
+
Use the defaults first:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
rasterport https://example.com --screenshot-only --out screenshot.json
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Use lower JPEG quality for smaller payloads:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
rasterport https://example.com --screenshot-only --quality 50 --out screenshot.json
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Use PNG only when exact pixel fidelity is needed:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
rasterport https://example.com --screenshot-only --image-format png --out screenshot.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Prefer `--screenshot-only` when the receiving model has vision and only needs
|
|
101
|
+
visible page state. Prefer `--dom-only` when the model only needs readable text,
|
|
102
|
+
links, and HTML structure. Prefer default output when the agent benefits from
|
|
103
|
+
both visual layout and DOM content.
|
|
104
|
+
|
|
105
|
+
## Decoding Screenshots
|
|
106
|
+
|
|
107
|
+
The `screenshot` field is base64. Agents or host applications can decode it to
|
|
108
|
+
an image file before passing it to a vision model.
|
|
109
|
+
|
|
110
|
+
Example JavaScript:
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
114
|
+
|
|
115
|
+
const result = JSON.parse(await readFile("screenshot.json", "utf8"));
|
|
116
|
+
await writeFile("screenshot.jpg", Buffer.from(result.screenshot, "base64"));
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## CLI Options
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
rasterport <url> [options]
|
|
123
|
+
|
|
124
|
+
--full-page Capture the full scrollable page
|
|
125
|
+
--width <number> Browser width (default: 1280)
|
|
126
|
+
--height <number> Browser height (default: 800)
|
|
127
|
+
--format <base64|buffer>
|
|
128
|
+
Screenshot output format (default: base64)
|
|
129
|
+
--image-format <png|jpeg>
|
|
130
|
+
Screenshot image format (default: jpeg)
|
|
131
|
+
--quality <number> JPEG quality from 1-100 (default: 70)
|
|
132
|
+
--out <file> Write JSON to a file instead of stdout
|
|
133
|
+
--screenshot-only Return screenshot, final URL, and viewport metadata
|
|
134
|
+
--dom-only Return DOM, final URL, and viewport metadata
|
|
135
|
+
--help Show help
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Notes For Agents
|
|
139
|
+
|
|
140
|
+
- The screenshot captures the page after Playwright's `networkidle` load state.
|
|
141
|
+
- The default viewport is 1280 by 800.
|
|
142
|
+
- The `url` field may differ from the input URL if the page redirects.
|
|
143
|
+
- `--screenshot-only` omits `dom`, but keeps `url` and `viewport` metadata.
|
|
144
|
+
- `--dom-only` omits `screenshot`, which avoids large base64 payloads.
|
|
145
|
+
- Use `--full-page` when evaluating landing pages, docs, profiles, or pages
|
|
146
|
+
where important content may appear below the first viewport.
|
|
147
|
+
- Use custom width and height when checking responsive behavior.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rasterport",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Minimal CLI to capture webpage screenshots and DOM for LLM workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
20
|
"README.md",
|
|
21
|
+
"llms.txt",
|
|
21
22
|
"LICENSE"
|
|
22
23
|
],
|
|
23
24
|
"scripts": {
|