rasterport 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rasterport contributors
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 ADDED
@@ -0,0 +1,37 @@
1
+ # rasterport
2
+
3
+ Minimal CLI for capturing a webpage screenshot and DOM as JSON.
4
+
5
+ ```bash
6
+ npx rasterport https://example.com
7
+ ```
8
+
9
+ ## Options
10
+
11
+ ```bash
12
+ rasterport <url> [options]
13
+
14
+ --full-page Capture the full scrollable page
15
+ --width <number> Browser width (default: 1280)
16
+ --height <number> Browser height (default: 800)
17
+ --format <base64|buffer>
18
+ Screenshot output format (default: base64)
19
+ --out <file> Write JSON to a file instead of stdout
20
+ --screenshot-only Return only the screenshot
21
+ --dom-only Return only the DOM
22
+ --help Show help
23
+ ```
24
+
25
+ The default output is JSON:
26
+
27
+ ```json
28
+ {
29
+ "screenshot": "<base64>",
30
+ "dom": "<html>...</html>",
31
+ "url": "https://example.com",
32
+ "viewport": {
33
+ "width": 1280,
34
+ "height": 800
35
+ }
36
+ }
37
+ ```
@@ -0,0 +1,2 @@
1
+ import { type Page } from "playwright";
2
+ export declare function withPage<T>(width: number, height: number, run: (page: Page) => Promise<T>): Promise<T>;
@@ -0,0 +1,13 @@
1
+ import { chromium } from "playwright";
2
+ export async function withPage(width, height, run) {
3
+ let browser;
4
+ try {
5
+ browser = await chromium.launch({ headless: true });
6
+ const page = await browser.newPage({ viewport: { width, height } });
7
+ return await run(page);
8
+ }
9
+ finally {
10
+ await browser?.close();
11
+ }
12
+ }
13
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA2B,MAAM,YAAY,CAAC;AAE/D,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,KAAa,EACb,MAAc,EACd,GAA+B;IAE/B,IAAI,OAA4B,CAAC;IAEjC,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACpE,OAAO,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { CaptureResult, CliOptions } from "./types.js";
2
+ export declare function capture(options: CliOptions): Promise<CaptureResult>;
@@ -0,0 +1,28 @@
1
+ import { withPage } from "./browser.js";
2
+ export async function capture(options) {
3
+ return withPage(options.width, options.height, async (page) => {
4
+ await page.goto(options.url, { waitUntil: "networkidle" });
5
+ const screenshot = options.domOnly
6
+ ? undefined
7
+ : await page.screenshot({ fullPage: options.fullPage });
8
+ const dom = options.screenshotOnly ? undefined : await page.content();
9
+ return {
10
+ screenshot: serializeScreenshot(screenshot, options.format),
11
+ dom,
12
+ url: page.url(),
13
+ viewport: {
14
+ width: options.width,
15
+ height: options.height,
16
+ },
17
+ };
18
+ });
19
+ }
20
+ function serializeScreenshot(screenshot, format) {
21
+ if (!screenshot) {
22
+ return undefined;
23
+ }
24
+ return format === "buffer"
25
+ ? Array.from(screenshot)
26
+ : screenshot.toString("base64");
27
+ }
28
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAmB;IAC/C,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC5D,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;QAE3D,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO;YAChC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAE1D,MAAM,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,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.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ import { capture } from "./capture.js";
3
+ import { outputResult } from "./serializer.js";
4
+ const DEFAULT_WIDTH = 1280;
5
+ const DEFAULT_HEIGHT = 800;
6
+ async function main() {
7
+ const options = parseArgs(process.argv.slice(2));
8
+ const result = await capture(options);
9
+ await outputResult(result, options);
10
+ }
11
+ function parseArgs(args) {
12
+ if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
13
+ printHelp();
14
+ process.exit(args.length === 0 ? 1 : 0);
15
+ }
16
+ const url = args[0];
17
+ if (!url || url.startsWith("-")) {
18
+ throw new Error("Expected a URL: rasterport <url> [options]");
19
+ }
20
+ const options = {
21
+ url,
22
+ fullPage: false,
23
+ width: DEFAULT_WIDTH,
24
+ height: DEFAULT_HEIGHT,
25
+ format: "base64",
26
+ screenshotOnly: false,
27
+ domOnly: false,
28
+ };
29
+ for (let index = 1; index < args.length; index += 1) {
30
+ const arg = args[index];
31
+ switch (arg) {
32
+ case "--full-page":
33
+ options.fullPage = true;
34
+ break;
35
+ case "--width":
36
+ options.width = parsePositiveNumber(readValue(args, ++index, arg), arg);
37
+ break;
38
+ case "--height":
39
+ options.height = parsePositiveNumber(readValue(args, ++index, arg), arg);
40
+ break;
41
+ case "--format":
42
+ options.format = parseFormat(readValue(args, ++index, arg));
43
+ break;
44
+ case "--out":
45
+ options.out = readValue(args, ++index, arg);
46
+ break;
47
+ case "--screenshot-only":
48
+ options.screenshotOnly = true;
49
+ break;
50
+ case "--dom-only":
51
+ options.domOnly = true;
52
+ break;
53
+ default:
54
+ throw new Error(`Unknown option: ${arg}`);
55
+ }
56
+ }
57
+ if (options.screenshotOnly && options.domOnly) {
58
+ throw new Error("Use either --screenshot-only or --dom-only, not both.");
59
+ }
60
+ return options;
61
+ }
62
+ function readValue(args, index, option) {
63
+ const value = args[index];
64
+ if (!value || value.startsWith("-")) {
65
+ throw new Error(`Expected a value after ${option}`);
66
+ }
67
+ return value;
68
+ }
69
+ function parsePositiveNumber(value, option) {
70
+ const number = Number(value);
71
+ if (!Number.isInteger(number) || number <= 0) {
72
+ throw new Error(`${option} must be a positive integer`);
73
+ }
74
+ return number;
75
+ }
76
+ function parseFormat(value) {
77
+ if (value === "base64" || value === "buffer") {
78
+ return value;
79
+ }
80
+ throw new Error("--format must be either base64 or buffer");
81
+ }
82
+ function printHelp() {
83
+ process.stdout.write(`rasterport <url> [options]
84
+
85
+ Options:
86
+ --full-page Capture the full scrollable page
87
+ --width <number> Browser width (default: ${DEFAULT_WIDTH})
88
+ --height <number> Browser height (default: ${DEFAULT_HEIGHT})
89
+ --format <base64|buffer>
90
+ Screenshot output format (default: base64)
91
+ --out <file> Write JSON to a file instead of stdout
92
+ --screenshot-only Return only the screenshot
93
+ --dom-only Return only the DOM
94
+ --help Show help
95
+ `);
96
+ }
97
+ main().catch((error) => {
98
+ const message = error instanceof Error ? error.message : String(error);
99
+ process.stderr.write(`rasterport: ${message}\n`);
100
+ process.exit(1);
101
+ });
102
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c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1
+ export { capture } from "./capture.js";
2
+ export type { CaptureResult, CliOptions, ScreenshotFormat } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { capture } from "./capture.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { CaptureResult, CliOptions } from "./types.js";
2
+ export declare function outputResult(result: CaptureResult, options: Pick<CliOptions, "out">): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ export async function outputResult(result, options) {
3
+ const json = JSON.stringify(result, null, 2);
4
+ if (options.out) {
5
+ await writeFile(options.out, `${json}\n`, "utf8");
6
+ return;
7
+ }
8
+ process.stdout.write(`${json}\n`);
9
+ }
10
+ //# sourceMappingURL=serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAqB,EACrB,OAAgC;IAEhC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE7C,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,EAAE,MAAM,CAAC,CAAC;QAClD,OAAO;IACT,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,20 @@
1
+ export type ScreenshotFormat = "base64" | "buffer";
2
+ export interface CliOptions {
3
+ url: string;
4
+ fullPage: boolean;
5
+ width: number;
6
+ height: number;
7
+ format: ScreenshotFormat;
8
+ out?: string;
9
+ screenshotOnly: boolean;
10
+ domOnly: boolean;
11
+ }
12
+ export interface CaptureResult {
13
+ screenshot?: string | number[];
14
+ dom?: string;
15
+ url: string;
16
+ viewport: {
17
+ width: number;
18
+ height: number;
19
+ };
20
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "rasterport",
3
+ "version": "0.1.0",
4
+ "description": "Minimal CLI to capture webpage screenshots and DOM for LLM workflows.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "bin": {
16
+ "rasterport": "./dist/cli.js"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "start": "node dist/cli.js",
26
+ "check": "tsc --noEmit",
27
+ "prepack": "npm run build",
28
+ "prepublishOnly": "npm run check"
29
+ },
30
+ "keywords": [
31
+ "playwright",
32
+ "screenshot",
33
+ "dom",
34
+ "cli",
35
+ "llm"
36
+ ],
37
+ "license": "MIT",
38
+ "dependencies": {
39
+ "playwright": "^1.44.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^20.12.7",
43
+ "typescript": "^5.4.5"
44
+ },
45
+ "engines": {
46
+ "node": ">=18"
47
+ }
48
+ }