screenshotty-js 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 +21 -0
- package/README.md +151 -0
- package/dist/client.d.ts +40 -0
- package/dist/client.js +111 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +15 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +104 -0
- package/dist/types.js +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nihey Takizawa
|
|
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,151 @@
|
|
|
1
|
+
# screenshotty-js
|
|
2
|
+
|
|
3
|
+
Official JavaScript / TypeScript client for the **[Screenshotty](https://screenshotty.link)** screenshot API β capture pixel-perfect screenshots and PDFs of any website or raw HTML with a single call.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/nihey/screenshotty-js/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/screenshotty-js)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
|
|
9
|
+
- πΈ Full-page, element, mobile, and PDF capture
|
|
10
|
+
- π Dark mode, ad-blocking, cookie-banner removal, geo-targeting
|
|
11
|
+
- π§© Zero runtime dependencies β uses the native `fetch` (Node 18+, Deno, Bun, browsers)
|
|
12
|
+
- π Fully typed options and results
|
|
13
|
+
|
|
14
|
+
> Powered by the [Screenshotty screenshot API](https://screenshotty.link). Grab a free API key (1,500 screenshots/month, no card) in the [dashboard](https://screenshotty.link) and read the full [API documentation](https://screenshotty.link/docs).
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install screenshotty-js
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Screenshotty } from "screenshotty-js";
|
|
26
|
+
|
|
27
|
+
const client = new Screenshotty(process.env.SCREENSHOTTY_API_KEY!);
|
|
28
|
+
|
|
29
|
+
// Get raw PNG bytes
|
|
30
|
+
const png = await client.capture({ url: "https://example.com", fullPage: true });
|
|
31
|
+
|
|
32
|
+
// β¦or just the hosted URL
|
|
33
|
+
const url = await client.captureToUrl({ url: "https://example.com" });
|
|
34
|
+
|
|
35
|
+
// β¦or write straight to disk (Node.js)
|
|
36
|
+
await client.captureToFile({ url: "https://example.com" }, "example.png");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Examples
|
|
40
|
+
|
|
41
|
+
**Mobile screenshot in dark mode:**
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
await client.capture({
|
|
45
|
+
url: "https://example.com",
|
|
46
|
+
viewportPreset: "iphone_15_pro_max",
|
|
47
|
+
lightMode: "dark",
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Website β PDF:**
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const pdf = await client.capture({
|
|
55
|
+
url: "https://example.com",
|
|
56
|
+
format: "application/pdf",
|
|
57
|
+
printed: true,
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Capture a single element, clean of ads and cookie banners:**
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
await client.capture({
|
|
65
|
+
url: "https://news.example.com/article",
|
|
66
|
+
selector: "article",
|
|
67
|
+
adblock: true,
|
|
68
|
+
blockCookieBanner: true,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Render raw HTML (great for OG images):**
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
await client.capture({
|
|
76
|
+
html: "<h1 style='font:700 64px sans-serif'>Hello π</h1>",
|
|
77
|
+
viewportWidth: 1200,
|
|
78
|
+
viewportHeight: 630,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Geo-targeted capture:**
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const countries = await client.countries(); // e.g. ["us", "de", "br", β¦]
|
|
86
|
+
await client.capture({ url: "https://example.com", country: "de" });
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## API
|
|
90
|
+
|
|
91
|
+
### `new Screenshotty(apiKey, options?)`
|
|
92
|
+
|
|
93
|
+
| Option | Type | Default |
|
|
94
|
+
|--------|------|---------|
|
|
95
|
+
| `baseUrl` | `string` | `https://api.screenshotty.link` |
|
|
96
|
+
| `fetch` | `typeof fetch` | global `fetch` |
|
|
97
|
+
|
|
98
|
+
### Methods
|
|
99
|
+
|
|
100
|
+
| Method | Returns | Notes |
|
|
101
|
+
|--------|---------|-------|
|
|
102
|
+
| `capture(options)` | `Promise<Uint8Array>` | Raw image/PDF bytes |
|
|
103
|
+
| `captureToJson(options)` | `Promise<ScreenshotResult>` | `{ url, width, height, mime }` |
|
|
104
|
+
| `captureToUrl(options)` | `Promise<string>` | Hosted screenshot URL |
|
|
105
|
+
| `captureToFile(options, path)` | `Promise<void>` | Node.js only |
|
|
106
|
+
| `countries()` | `Promise<string[]>` | Geo-targeting country codes |
|
|
107
|
+
|
|
108
|
+
### `ScreenshotOptions`
|
|
109
|
+
|
|
110
|
+
camelCase options are mapped to the API's parameters automatically. See the full,
|
|
111
|
+
always-current parameter reference in the [Screenshotty API docs](https://screenshotty.link/docs). Highlights: `url` / `html`,
|
|
112
|
+
`format`, `fullPage`, `selector`, `viewportWidth` / `viewportHeight` /
|
|
113
|
+
`viewportPreset`, `deviceScaleFactor`, `crop*`, `lightMode`, `adblock`,
|
|
114
|
+
`blockCookieBanner`, `country`, `javascriptCode` / `cssCode`, `httpHeaders` /
|
|
115
|
+
`cookies`, `readyEvent` / `waitMs`, `webhookUrl`.
|
|
116
|
+
|
|
117
|
+
### Errors
|
|
118
|
+
|
|
119
|
+
Non-2xx responses throw a `ScreenshottyError` with `.status` and `.body`:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { ScreenshottyError } from "screenshotty-js";
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
await client.capture({ url: "https://example.com" });
|
|
126
|
+
} catch (err) {
|
|
127
|
+
if (err instanceof ScreenshottyError) {
|
|
128
|
+
console.error(err.status, err.message, err.body);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm install
|
|
137
|
+
npm run typecheck
|
|
138
|
+
npm test # node --test with a mocked fetch
|
|
139
|
+
npm run build
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Links
|
|
143
|
+
|
|
144
|
+
- π [Screenshotty](https://screenshotty.link) β the screenshot API
|
|
145
|
+
- π [API documentation](https://screenshotty.link/docs)
|
|
146
|
+
- π§ͺ [Interactive playground](https://screenshotty.link/screenshot-api)
|
|
147
|
+
- π¦ [@screenshotty](https://x.com/screenshotty)
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
[MIT](./LICENSE) Β© Nihey Takizawa
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ScreenshotOptions, ScreenshotResult } from "./types.js";
|
|
2
|
+
/** Configuration for a {@link Screenshotty} client. */
|
|
3
|
+
export interface ScreenshottyClientOptions {
|
|
4
|
+
/** Override the API base URL. Default: `https://api.screenshotty.link`. */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Custom fetch implementation (defaults to the global `fetch`). */
|
|
7
|
+
fetch?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Client for the Screenshotty screenshot API.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const client = new Screenshotty(process.env.SCREENSHOTTY_API_KEY!);
|
|
15
|
+
* const png = await client.capture({ url: "https://example.com", fullPage: true });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @see https://screenshotty.link/docs
|
|
19
|
+
*/
|
|
20
|
+
export declare class Screenshotty {
|
|
21
|
+
private readonly apiKey;
|
|
22
|
+
private readonly baseUrl;
|
|
23
|
+
private readonly fetchImpl;
|
|
24
|
+
constructor(apiKey: string, options?: ScreenshottyClientOptions);
|
|
25
|
+
/** Capture a screenshot and return the raw image (or PDF) bytes. */
|
|
26
|
+
capture(options: ScreenshotOptions): Promise<Uint8Array>;
|
|
27
|
+
/** Capture and return the result metadata (`{ url, width, height, mime }`). */
|
|
28
|
+
captureToJson(options: ScreenshotOptions): Promise<ScreenshotResult>;
|
|
29
|
+
/** Capture and return just the stored screenshot URL. */
|
|
30
|
+
captureToUrl(options: ScreenshotOptions): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Capture and write the bytes to a file. Node.js only.
|
|
33
|
+
* @param filePath Destination path.
|
|
34
|
+
*/
|
|
35
|
+
captureToFile(options: ScreenshotOptions, filePath: string): Promise<void>;
|
|
36
|
+
/** List the country codes available for geo-targeted captures. */
|
|
37
|
+
countries(): Promise<string[]>;
|
|
38
|
+
private request;
|
|
39
|
+
private rawFetch;
|
|
40
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ScreenshottyError } from "./errors.js";
|
|
2
|
+
const DEFAULT_BASE_URL = "https://api.screenshotty.link";
|
|
3
|
+
const SCREENSHOT_PATH = "/api/v1/screenshot";
|
|
4
|
+
const COUNTRIES_PATH = "/api/v1/screenshot/countries";
|
|
5
|
+
/** camelCase β snake_case (e.g. `viewportWidth` β `viewport_width`). */
|
|
6
|
+
function toSnakeCase(key) {
|
|
7
|
+
return key.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);
|
|
8
|
+
}
|
|
9
|
+
function toRequestBody(options) {
|
|
10
|
+
const body = {};
|
|
11
|
+
for (const [key, value] of Object.entries(options)) {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
continue;
|
|
14
|
+
body[toSnakeCase(key)] = value;
|
|
15
|
+
}
|
|
16
|
+
return body;
|
|
17
|
+
}
|
|
18
|
+
function extractMessage(body) {
|
|
19
|
+
if (body && typeof body === "object") {
|
|
20
|
+
const record = body;
|
|
21
|
+
if (typeof record.error === "string")
|
|
22
|
+
return record.error;
|
|
23
|
+
if (typeof record.message === "string")
|
|
24
|
+
return record.message;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Client for the Screenshotty screenshot API.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const client = new Screenshotty(process.env.SCREENSHOTTY_API_KEY!);
|
|
34
|
+
* const png = await client.capture({ url: "https://example.com", fullPage: true });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @see https://screenshotty.link/docs
|
|
38
|
+
*/
|
|
39
|
+
export class Screenshotty {
|
|
40
|
+
apiKey;
|
|
41
|
+
baseUrl;
|
|
42
|
+
fetchImpl;
|
|
43
|
+
constructor(apiKey, options = {}) {
|
|
44
|
+
if (!apiKey) {
|
|
45
|
+
throw new Error("Screenshotty: an API key is required. Get one at https://screenshotty.link.");
|
|
46
|
+
}
|
|
47
|
+
this.apiKey = apiKey;
|
|
48
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
49
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
50
|
+
if (typeof fetchImpl !== "function") {
|
|
51
|
+
throw new Error("Screenshotty: no fetch implementation found. Use Node 18+ or pass `options.fetch`.");
|
|
52
|
+
}
|
|
53
|
+
this.fetchImpl = fetchImpl;
|
|
54
|
+
}
|
|
55
|
+
/** Capture a screenshot and return the raw image (or PDF) bytes. */
|
|
56
|
+
async capture(options) {
|
|
57
|
+
const res = await this.request({ ...options, responseType: "image" });
|
|
58
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
59
|
+
}
|
|
60
|
+
/** Capture and return the result metadata (`{ url, width, height, mime }`). */
|
|
61
|
+
async captureToJson(options) {
|
|
62
|
+
const res = await this.request({ ...options, responseType: "json" });
|
|
63
|
+
return (await res.json());
|
|
64
|
+
}
|
|
65
|
+
/** Capture and return just the stored screenshot URL. */
|
|
66
|
+
async captureToUrl(options) {
|
|
67
|
+
const result = await this.captureToJson(options);
|
|
68
|
+
return result.url;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Capture and write the bytes to a file. Node.js only.
|
|
72
|
+
* @param filePath Destination path.
|
|
73
|
+
*/
|
|
74
|
+
async captureToFile(options, filePath) {
|
|
75
|
+
const bytes = await this.capture(options);
|
|
76
|
+
const { writeFile } = await import("node:fs/promises");
|
|
77
|
+
await writeFile(filePath, bytes);
|
|
78
|
+
}
|
|
79
|
+
/** List the country codes available for geo-targeted captures. */
|
|
80
|
+
async countries() {
|
|
81
|
+
const res = await this.rawFetch(COUNTRIES_PATH, { method: "GET" });
|
|
82
|
+
const data = (await res.json());
|
|
83
|
+
return data.countries ?? [];
|
|
84
|
+
}
|
|
85
|
+
request(options) {
|
|
86
|
+
return this.rawFetch(SCREENSHOT_PATH, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: { "content-type": "application/json" },
|
|
89
|
+
body: JSON.stringify(toRequestBody(options)),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async rawFetch(path, init) {
|
|
93
|
+
const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
94
|
+
...init,
|
|
95
|
+
headers: { "x-api-key": this.apiKey, ...(init.headers ?? {}) },
|
|
96
|
+
});
|
|
97
|
+
if (!res.ok) {
|
|
98
|
+
const text = await res.text();
|
|
99
|
+
let body = text;
|
|
100
|
+
try {
|
|
101
|
+
body = JSON.parse(text);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
/* keep raw text */
|
|
105
|
+
}
|
|
106
|
+
const message = extractMessage(body) ?? `Screenshotty request failed with status ${res.status}.`;
|
|
107
|
+
throw new ScreenshottyError(message, res.status, body);
|
|
108
|
+
}
|
|
109
|
+
return res;
|
|
110
|
+
}
|
|
111
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Error thrown when the Screenshotty API responds with a non-2xx status. */
|
|
2
|
+
export declare class ScreenshottyError extends Error {
|
|
3
|
+
/** HTTP status code of the failed response. */
|
|
4
|
+
readonly status: number;
|
|
5
|
+
/** Parsed JSON body if available, otherwise the raw response text. */
|
|
6
|
+
readonly body: unknown;
|
|
7
|
+
constructor(message: string, status: number, body: unknown);
|
|
8
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Error thrown when the Screenshotty API responds with a non-2xx status. */
|
|
2
|
+
export class ScreenshottyError extends Error {
|
|
3
|
+
/** HTTP status code of the failed response. */
|
|
4
|
+
status;
|
|
5
|
+
/** Parsed JSON body if available, otherwise the raw response text. */
|
|
6
|
+
body;
|
|
7
|
+
constructor(message, status, body) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "ScreenshottyError";
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.body = body;
|
|
12
|
+
// Restore prototype chain for instanceof across transpile targets.
|
|
13
|
+
Object.setPrototypeOf(this, ScreenshottyError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Screenshotty } from "./client.js";
|
|
2
|
+
export type { ScreenshottyClientOptions } from "./client.js";
|
|
3
|
+
export { ScreenshottyError } from "./errors.js";
|
|
4
|
+
export type { ScreenshotOptions, ScreenshotResult, ImageFormat, ResponseType, ReadyEvent, LightMode, ViewportPreset, WebhookMethod, Cookie, } from "./types.js";
|
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formats supported by the Screenshotty API.
|
|
3
|
+
* @see https://screenshotty.link/docs
|
|
4
|
+
*/
|
|
5
|
+
export type ImageFormat = "image/png" | "image/jpg" | "image/jpeg" | "image/gif" | "image/webp" | "image/jp2" | "image/tiff" | "application/pdf";
|
|
6
|
+
/** How the API should return the result. High-level client methods set this for you. */
|
|
7
|
+
export type ResponseType = "image" | "json" | "url" | "redirect" | "file";
|
|
8
|
+
/** Page-lifecycle event to wait for before capturing. */
|
|
9
|
+
export type ReadyEvent = "load" | "domcontentloaded" | "networkidle" | "networkidle2" | "networkidle0";
|
|
10
|
+
/** Force the page's color scheme. */
|
|
11
|
+
export type LightMode = "default" | "light" | "dark";
|
|
12
|
+
/** Named device/viewport presets. */
|
|
13
|
+
export type ViewportPreset = "desktop" | "desktop_hd" | "desktop_4k" | "tablet" | "tablet_landscape" | "mobile" | "mobile_landscape" | "mobile_android" | "mobile_android_landscape" | "iphone_se" | "iphone_14" | "iphone_14_pro" | "iphone_14_pro_max" | "iphone_15" | "iphone_15_pro_max";
|
|
14
|
+
/** HTTP method used to deliver the webhook callback. */
|
|
15
|
+
export type WebhookMethod = "GET" | "POST" | "PUT" | "PATCH";
|
|
16
|
+
/** A cookie to set before loading the page (used for capturing authenticated pages). */
|
|
17
|
+
export interface Cookie {
|
|
18
|
+
name: string;
|
|
19
|
+
value: string;
|
|
20
|
+
domain?: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for a screenshot request. All keys are camelCase and mapped to the
|
|
26
|
+
* API's snake_case parameters automatically. Provide either `url` or `html`.
|
|
27
|
+
*/
|
|
28
|
+
export interface ScreenshotOptions {
|
|
29
|
+
/** URL of the page to capture. Mutually exclusive with `html`. */
|
|
30
|
+
url?: string;
|
|
31
|
+
/** Raw HTML to render and capture. Mutually exclusive with `url`. */
|
|
32
|
+
html?: string;
|
|
33
|
+
/** Output format. Default: `image/png`. */
|
|
34
|
+
format?: ImageFormat;
|
|
35
|
+
/** Viewport width in px. Default: 1920. */
|
|
36
|
+
viewportWidth?: number;
|
|
37
|
+
/** Viewport height in px. Default: 1080. */
|
|
38
|
+
viewportHeight?: number;
|
|
39
|
+
/** Named viewport/device preset (overrides width/height). */
|
|
40
|
+
viewportPreset?: ViewportPreset;
|
|
41
|
+
/** Device pixel ratio. Default: 1. */
|
|
42
|
+
deviceScaleFactor?: number;
|
|
43
|
+
/** Crop origin X (px). */
|
|
44
|
+
cropX?: number;
|
|
45
|
+
/** Crop origin Y (px). */
|
|
46
|
+
cropY?: number;
|
|
47
|
+
/** Crop width (px). */
|
|
48
|
+
cropWidth?: number;
|
|
49
|
+
/** Crop height (px). */
|
|
50
|
+
cropHeight?: number;
|
|
51
|
+
/** Capture a single element by CSS selector instead of the page. */
|
|
52
|
+
selector?: string;
|
|
53
|
+
/** Capture the full scrollable page. Default: true. */
|
|
54
|
+
fullPage?: boolean;
|
|
55
|
+
/** Transparent background (PNG/WebP). Default: false. */
|
|
56
|
+
transparentBackground?: boolean;
|
|
57
|
+
/** Scroll to the bottom before capture (triggers lazy loading). Default: false. */
|
|
58
|
+
scrollToBottom?: boolean;
|
|
59
|
+
/** Use print CSS/media. Default: false. */
|
|
60
|
+
printed?: boolean;
|
|
61
|
+
/** Lifecycle event to wait for. Default: `domcontentloaded`. */
|
|
62
|
+
readyEvent?: ReadyEvent;
|
|
63
|
+
/** Extra fixed wait in ms after the ready event. */
|
|
64
|
+
waitMs?: number;
|
|
65
|
+
/** JavaScript to inject and run before capture. */
|
|
66
|
+
javascriptCode?: string;
|
|
67
|
+
/** CSS to inject before capture. */
|
|
68
|
+
cssCode?: string;
|
|
69
|
+
/** Override the User-Agent header. */
|
|
70
|
+
userAgent?: string;
|
|
71
|
+
/** Locale/language (e.g. `en-US`). Default: `en-US`. */
|
|
72
|
+
language?: string;
|
|
73
|
+
/** Cookies to set before loading (capture authed pages). */
|
|
74
|
+
cookies?: Cookie[];
|
|
75
|
+
/** Extra HTTP request headers. */
|
|
76
|
+
httpHeaders?: Record<string, string>;
|
|
77
|
+
/** Block ads. Default: false. */
|
|
78
|
+
adblock?: boolean;
|
|
79
|
+
/** Auto-dismiss cookie-consent banners. Default: false. */
|
|
80
|
+
blockCookieBanner?: boolean;
|
|
81
|
+
/** Force color scheme. Default: `default`. */
|
|
82
|
+
lightMode?: LightMode;
|
|
83
|
+
/** Route the request through a proxy in this country (ISO code). */
|
|
84
|
+
country?: string;
|
|
85
|
+
/** Webhook URL to call when the screenshot is ready. */
|
|
86
|
+
webhookUrl?: string;
|
|
87
|
+
/** Webhook HTTP method. Default: `POST`. */
|
|
88
|
+
webhookMethod?: WebhookMethod;
|
|
89
|
+
/** Extra headers to send with the webhook call. */
|
|
90
|
+
webhookHeaders?: Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
/** Result returned by `captureToJson` / `captureToUrl` (`response_type=json|url`). */
|
|
93
|
+
export interface ScreenshotResult {
|
|
94
|
+
/** Public URL of the stored screenshot. */
|
|
95
|
+
url: string;
|
|
96
|
+
/** Rendered width in px, when available. */
|
|
97
|
+
width?: number;
|
|
98
|
+
/** Rendered height in px, when available. */
|
|
99
|
+
height?: number;
|
|
100
|
+
/** MIME type of the stored file, when available. */
|
|
101
|
+
mime?: string;
|
|
102
|
+
/** Extracted HTML, when requested. */
|
|
103
|
+
html?: string;
|
|
104
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "screenshotty-js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official JavaScript/TypeScript client for the Screenshotty screenshot API β capture pixel-perfect screenshots and PDFs of any website or HTML.",
|
|
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
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "node --import tsx --test test/*.test.ts",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"screenshot",
|
|
27
|
+
"screenshot-api",
|
|
28
|
+
"website-screenshot",
|
|
29
|
+
"html-to-image",
|
|
30
|
+
"html-to-pdf",
|
|
31
|
+
"puppeteer",
|
|
32
|
+
"playwright",
|
|
33
|
+
"url-to-image",
|
|
34
|
+
"og-image",
|
|
35
|
+
"pdf"
|
|
36
|
+
],
|
|
37
|
+
"homepage": "https://screenshotty.link",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/nihey/screenshotty-js.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/nihey/screenshotty-js/issues"
|
|
44
|
+
},
|
|
45
|
+
"author": "Nihey Takizawa",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^22.10.0",
|
|
55
|
+
"tsx": "^4.19.2",
|
|
56
|
+
"typescript": "^5.7.2"
|
|
57
|
+
}
|
|
58
|
+
}
|