grabshot-sdk 1.0.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 +73 -0
- package/index.d.ts +19 -0
- package/index.js +91 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GrabShot
|
|
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,73 @@
|
|
|
1
|
+
# grabshot
|
|
2
|
+
|
|
3
|
+
Capture website screenshots with a simple Node.js API. No headless browser required.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install grabshot-api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const GrabShot = require('grabshot-api');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
|
|
17
|
+
const client = new GrabShot('your-api-key');
|
|
18
|
+
|
|
19
|
+
// Take a screenshot
|
|
20
|
+
const image = await client.screenshot('https://github.com');
|
|
21
|
+
fs.writeFileSync('github.png', image);
|
|
22
|
+
|
|
23
|
+
// Full page capture
|
|
24
|
+
const full = await client.screenshot('https://example.com', {
|
|
25
|
+
fullPage: true,
|
|
26
|
+
width: 1440,
|
|
27
|
+
format: 'webp'
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Custom viewport (mobile)
|
|
31
|
+
const mobile = await client.screenshot('https://example.com', {
|
|
32
|
+
width: 375,
|
|
33
|
+
height: 812,
|
|
34
|
+
format: 'jpeg'
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
### `new GrabShot(apiKey, options?)`
|
|
41
|
+
|
|
42
|
+
- `apiKey` - Your API key ([get one free](https://grabshot.dev))
|
|
43
|
+
- `options.baseUrl` - Custom API URL (default: `https://grabshot.dev`)
|
|
44
|
+
|
|
45
|
+
### `.screenshot(url, options?)`
|
|
46
|
+
|
|
47
|
+
Returns a `Promise<Buffer>` with the screenshot image.
|
|
48
|
+
|
|
49
|
+
| Option | Type | Default | Description |
|
|
50
|
+
|--------|------|---------|-------------|
|
|
51
|
+
| `width` | number | 1440 | Viewport width in pixels |
|
|
52
|
+
| `height` | number | 900 | Viewport height in pixels |
|
|
53
|
+
| `format` | string | `'png'` | Output format: `png`, `jpeg`, `webp` |
|
|
54
|
+
| `fullPage` | boolean | `false` | Capture full scrollable page |
|
|
55
|
+
| `delay` | number | `0` | Wait ms before capture |
|
|
56
|
+
| `aiCleanup` | boolean | `false` | AI-powered cleanup (paid plans) |
|
|
57
|
+
|
|
58
|
+
### `.ogImage(url, options?)`
|
|
59
|
+
|
|
60
|
+
Generate an Open Graph image for a URL. Returns `Promise<Buffer>`.
|
|
61
|
+
|
|
62
|
+
## Pricing
|
|
63
|
+
|
|
64
|
+
- **Free**: 25 screenshots/month
|
|
65
|
+
- **Starter** ($9/mo): 2,500 screenshots/month + AI cleanup
|
|
66
|
+
- **Pro** ($29/mo): 15,000 screenshots/month + priority
|
|
67
|
+
- **Business** ($79/mo): 50,000 screenshots/month + dedicated support
|
|
68
|
+
|
|
69
|
+
[Sign up free at grabshot.dev](https://grabshot.dev)
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare class GrabShot {
|
|
2
|
+
constructor(apiKey: string, options?: { baseUrl?: string });
|
|
3
|
+
|
|
4
|
+
screenshot(url: string, options?: {
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
format?: 'png' | 'jpeg' | 'webp';
|
|
8
|
+
fullPage?: boolean;
|
|
9
|
+
delay?: number;
|
|
10
|
+
aiCleanup?: boolean;
|
|
11
|
+
}): Promise<Buffer>;
|
|
12
|
+
|
|
13
|
+
ogImage(url: string, options?: {
|
|
14
|
+
template?: string;
|
|
15
|
+
}): Promise<Buffer>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export = GrabShot;
|
|
19
|
+
export { GrabShot };
|
package/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const http = require('http');
|
|
3
|
+
|
|
4
|
+
class GrabShot {
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} apiKey - Your GrabShot API key (get one free at grabshot.dev)
|
|
7
|
+
* @param {object} [options]
|
|
8
|
+
* @param {string} [options.baseUrl] - API base URL (default: https://grabshot.dev)
|
|
9
|
+
*/
|
|
10
|
+
constructor(apiKey, options = {}) {
|
|
11
|
+
if (!apiKey) throw new Error('API key required. Get one free at https://grabshot.dev');
|
|
12
|
+
this.apiKey = apiKey;
|
|
13
|
+
this.baseUrl = (options.baseUrl || 'https://grabshot.dev').replace(/\/$/, '');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Capture a screenshot of a URL
|
|
18
|
+
* @param {string} url - URL to screenshot
|
|
19
|
+
* @param {object} [options]
|
|
20
|
+
* @param {number} [options.width=1440] - Viewport width
|
|
21
|
+
* @param {number} [options.height=900] - Viewport height
|
|
22
|
+
* @param {string} [options.format=png] - Output format (png, jpeg, webp)
|
|
23
|
+
* @param {boolean} [options.fullPage=false] - Capture full scrollable page
|
|
24
|
+
* @param {number} [options.delay=0] - Wait ms before capture
|
|
25
|
+
* @param {boolean} [options.aiCleanup=false] - AI-powered cleanup (paid plans)
|
|
26
|
+
* @returns {Promise<Buffer>} Screenshot image buffer
|
|
27
|
+
*/
|
|
28
|
+
async screenshot(url, options = {}) {
|
|
29
|
+
const params = new URLSearchParams({
|
|
30
|
+
url,
|
|
31
|
+
apiKey: this.apiKey,
|
|
32
|
+
width: String(options.width || 1440),
|
|
33
|
+
height: String(options.height || 900),
|
|
34
|
+
format: options.format || 'png',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (options.fullPage) params.set('fullPage', 'true');
|
|
38
|
+
if (options.delay) params.set('delay', String(options.delay));
|
|
39
|
+
if (options.aiCleanup) params.set('aiCleanup', 'true');
|
|
40
|
+
|
|
41
|
+
const reqUrl = `${this.baseUrl}/v1/screenshot?${params}`;
|
|
42
|
+
return this._request(reqUrl);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate an OG image for a URL
|
|
47
|
+
* @param {string} url - URL to generate OG image for
|
|
48
|
+
* @param {object} [options]
|
|
49
|
+
* @param {string} [options.template] - OG template name
|
|
50
|
+
* @returns {Promise<Buffer>} OG image buffer
|
|
51
|
+
*/
|
|
52
|
+
async ogImage(url, options = {}) {
|
|
53
|
+
const params = new URLSearchParams({
|
|
54
|
+
url,
|
|
55
|
+
apiKey: this.apiKey,
|
|
56
|
+
});
|
|
57
|
+
if (options.template) params.set('template', options.template);
|
|
58
|
+
|
|
59
|
+
const reqUrl = `${this.baseUrl}/v1/og?${params}`;
|
|
60
|
+
return this._request(reqUrl);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @private */
|
|
64
|
+
_request(url) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const mod = url.startsWith('https') ? https : http;
|
|
67
|
+
mod.get(url, (res) => {
|
|
68
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
69
|
+
return this._request(res.headers.location).then(resolve, reject);
|
|
70
|
+
}
|
|
71
|
+
if (res.statusCode !== 200) {
|
|
72
|
+
let body = '';
|
|
73
|
+
res.on('data', (c) => body += c);
|
|
74
|
+
res.on('end', () => {
|
|
75
|
+
try { body = JSON.parse(body); } catch {}
|
|
76
|
+
reject(new Error(body.error || body.message || `HTTP ${res.statusCode}`));
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const chunks = [];
|
|
81
|
+
res.on('data', (c) => chunks.push(c));
|
|
82
|
+
res.on('end', () => resolve(Buffer.concat(chunks)));
|
|
83
|
+
res.on('error', reject);
|
|
84
|
+
}).on('error', reject);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = GrabShot;
|
|
90
|
+
module.exports.default = GrabShot;
|
|
91
|
+
module.exports.GrabShot = GrabShot;
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "grabshot-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Capture website screenshots with a simple API. Free tier included.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"screenshot",
|
|
9
|
+
"website screenshot",
|
|
10
|
+
"webpage capture",
|
|
11
|
+
"url to image",
|
|
12
|
+
"screenshot api",
|
|
13
|
+
"web capture",
|
|
14
|
+
"html to image",
|
|
15
|
+
"page screenshot",
|
|
16
|
+
"og image",
|
|
17
|
+
"social preview",
|
|
18
|
+
"puppeteer alternative",
|
|
19
|
+
"headless browser",
|
|
20
|
+
"website thumbnail"
|
|
21
|
+
],
|
|
22
|
+
"author": "GrabShot <hello@grabshot.dev>",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"homepage": "https://grabshot.dev",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/aitaskorchestra/grabshot-sdk"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/aitaskorchestra/grabshot-sdk/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=14"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"index.js",
|
|
37
|
+
"index.d.ts",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
]
|
|
41
|
+
}
|