@browserless/screenshot 10.9.17 → 10.9.18

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.
Files changed (2) hide show
  1. package/README.md +227 -6
  2. package/package.json +15 -10
package/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  <div align="center">
2
- <br>
3
2
  <img style="width: 500px; margin:3rem 0 1.5rem;" src="https://github.com/microlinkhq/browserless/raw/master/static/logo-banner.png#gh-light-mode-only" alt="browserless">
4
3
  <img style="width: 500px; margin:3rem 0 1.5rem;" src="https://github.com/microlinkhq/browserless/raw/master/static/logo-banner-light.png#gh-dark-mode-only" alt="browserless">
5
- <br>
6
- <br>
7
- <p align="center"><strong>@browserless/screenshot</strong>: Take a clean screenshot of any website.</p>
8
- <p align="center">See our <a href="https://browserless.js.org" target='_blank' rel='noopener noreferrer'>website</a> for more information.</p>
9
- <br>
4
+ <br><br>
5
+ <a href="https://microlink.io"><img src="https://img.shields.io/badge/powered_by-microlink.io-blue?style=flat-square&color=%23EA407B" alt="Powered by microlink.io"></a>
6
+ <img src="https://img.shields.io/github/tag/microlinkhq/browserless.svg?style=flat-square" alt="Last version">
7
+ <a href="https://coveralls.io/github/microlinkhq/browserless"><img src="https://img.shields.io/coveralls/microlinkhq/browserless.svg?style=flat-square" alt="Coverage Status"></a>
8
+ <a href="https://www.npmjs.org/package/browserless"><img src="https://img.shields.io/npm/dm/browserless.svg?style=flat-square" alt="NPM Status"></a>
9
+ <br><br>
10
10
  </div>
11
11
 
12
+ > @browserless/screenshot: Take a clean screenshot of any website.
13
+
14
+ See the [screenshot section](https://browserless.js.org/#/?id=screenshoturl-options) on our website for more information.
15
+
12
16
  ## Install
13
17
 
14
18
  Using npm:
@@ -17,6 +21,223 @@ Using npm:
17
21
  npm install @browserless/screenshot --save
18
22
  ```
19
23
 
24
+ ## About
25
+
26
+ This package provides **advanced screenshot capture** with smart defaults, browser frame overlays, gradient backgrounds, and automatic code syntax highlighting. It wraps Puppeteer's `page.screenshot()` with features optimized for production use.
27
+
28
+ ### What This Package Does
29
+
30
+ The `@browserless/screenshot` package allows you to:
31
+
32
+ - **Capture screenshots** with device emulation and smart waiting
33
+ - **Add browser frame overlays** (dark or light theme)
34
+ - **Apply gradient or image backgrounds** for social media-ready images
35
+ - **Auto-detect blank screenshots** and retry until content renders
36
+ - **Syntax highlight code** (JSON, text) with Prism.js themes
37
+ - **Capture specific elements** using CSS selectors
38
+ - **Take full-page screenshots** with lazy-loaded content support
39
+
40
+ ### Usage
41
+
42
+ ```js
43
+ const createScreenshot = require('@browserless/screenshot')
44
+ const createGoto = require('@browserless/goto')
45
+
46
+ const goto = createGoto({ timeout: 30000 })
47
+ const screenshot = createScreenshot({ goto })
48
+
49
+ // With browserless
50
+ const browserless = await browser.createContext()
51
+ const buffer = await browserless.screenshot('https://example.com')
52
+
53
+ // With overlay
54
+ const buffer = await browserless.screenshot('https://example.com', {
55
+ overlay: {
56
+ browser: 'dark',
57
+ background: 'linear-gradient(45deg, #FF057C 0%, #8D0B93 50%, #321575 100%)'
58
+ }
59
+ })
60
+ ```
61
+
62
+ ### Options
63
+
64
+ | Option | Type | Default | Description |
65
+ |--------|------|---------|-------------|
66
+ | `type` | `string` | `'png'` | Image format: `'png'`, `'jpeg'`, `'webp'` |
67
+ | `quality` | `number` | — | Quality (0-100) for JPEG/WebP |
68
+ | `fullPage` | `boolean` | `false` | Capture full scrollable page |
69
+ | `element` | `string` | — | CSS selector for element screenshot |
70
+ | `codeScheme` | `string` | `'atom-dark'` | Prism.js theme for code highlighting |
71
+ | `waitUntil` | `string` | `'auto'` | When to consider navigation done |
72
+ | `overlay` | `object` | `{}` | Browser overlay options |
73
+
74
+ All [Puppeteer page.screenshot() options](https://pptr.dev/api/puppeteer.screenshotoptions) are supported.
75
+
76
+ ### Browser Overlay
77
+
78
+ Add a browser frame around your screenshot for a polished look:
79
+
80
+ ```js
81
+ const buffer = await browserless.screenshot(url, {
82
+ overlay: {
83
+ // Browser frame theme: 'dark' or 'light'
84
+ browser: 'dark',
85
+
86
+ // Background: color, gradient, or image URL
87
+ background: 'linear-gradient(225deg, #FF057C 0%, #8D0B93 50%, #321575 100%)',
88
+
89
+ // Margin around the screenshot (default: 0.2 = 20%)
90
+ margin: 0.2
91
+ }
92
+ })
93
+ ```
94
+
95
+ #### Background Options
96
+
97
+ ```js
98
+ // Solid color
99
+ overlay: { background: '#c1c1c1' }
100
+
101
+ // CSS gradient
102
+ overlay: { background: 'linear-gradient(45deg, #12c2e9, #c471ed, #f64f59)' }
103
+
104
+ // Image URL
105
+ overlay: { background: 'https://source.unsplash.com/random/1920x1080' }
106
+ ```
107
+
108
+ ### Element Screenshots
109
+
110
+ Capture a specific DOM element:
111
+
112
+ ```js
113
+ const buffer = await browserless.screenshot(url, {
114
+ element: '.hero-section'
115
+ })
116
+
117
+ // The package waits for the element to be visible
118
+ const buffer = await browserless.screenshot(url, {
119
+ element: '#main-content'
120
+ })
121
+ ```
122
+
123
+ ### Full Page Screenshots
124
+
125
+ Capture the entire scrollable page with lazy-loaded content:
126
+
127
+ ```js
128
+ const buffer = await browserless.screenshot(url, {
129
+ fullPage: true
130
+ })
131
+ ```
132
+
133
+ The package automatically:
134
+ 1. Waits for DOM stability
135
+ 2. Scrolls through the page to trigger lazy-loaded images
136
+ 3. Scrolls back to top
137
+ 4. Takes the screenshot
138
+
139
+ ### Code Syntax Highlighting
140
+
141
+ When the response is JSON or plain text, the package automatically renders it with syntax highlighting:
142
+
143
+ ```js
144
+ // Screenshot of a JSON API response
145
+ const buffer = await browserless.screenshot('https://api.example.com/data', {
146
+ codeScheme: 'atom-dark' // or any Prism.js theme
147
+ })
148
+ ```
149
+
150
+ Available themes from [prism-themes](https://github.com/PrismJS/prism-themes):
151
+ - `atom-dark`, `ghcolors`, `dracula`, `duotone-dark`, `duotone-light`, `material-dark`, `material-light`, `nord`, `synthwave84`, and more
152
+
153
+ ### Smart Content Detection
154
+
155
+ When `waitUntil: 'auto'` (the default), the package:
156
+
157
+ 1. Navigates to the page
158
+ 2. Waits for fonts to load
159
+ 3. Waits for images in viewport to decode
160
+ 4. Takes a screenshot
161
+ 5. If the screenshot is blank/white, retries with additional waiting
162
+
163
+ This ensures JavaScript-rendered content is fully loaded.
164
+
165
+ ### Examples
166
+
167
+ #### Social media card
168
+
169
+ ```js
170
+ const buffer = await browserless.screenshot('https://example.com', {
171
+ device: 'iPhone 13',
172
+ overlay: {
173
+ browser: 'light',
174
+ background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'
175
+ }
176
+ })
177
+ ```
178
+
179
+ #### API documentation screenshot
180
+
181
+ ```js
182
+ const buffer = await browserless.screenshot('https://api.example.com/docs', {
183
+ fullPage: true,
184
+ type: 'jpeg',
185
+ quality: 85
186
+ })
187
+ ```
188
+
189
+ #### Specific component
190
+
191
+ ```js
192
+ const buffer = await browserless.screenshot('https://example.com', {
193
+ element: '[data-testid="pricing-table"]',
194
+ type: 'png'
195
+ })
196
+ ```
197
+
198
+ ### Architecture
199
+
200
+ ```
201
+ @browserless/screenshot
202
+ ├── src/
203
+ │ ├── index.js → Main screenshot logic with smart waiting
204
+ │ ├── is-white-screenshot.js → Blank screenshot detection using Jimp
205
+ │ ├── time-span.js → Timing utility
206
+ │ ├── overlay/
207
+ │ │ ├── index.js → Browser frame and background composition
208
+ │ │ ├── dark.png → Dark browser frame
209
+ │ │ └── light.png → Light browser frame
210
+ │ └── pretty/
211
+ │ ├── index.js → Code content detection and rendering
212
+ │ ├── html.js → HTML template for code display
213
+ │ ├── prism.js → Prism.js syntax highlighter
214
+ │ └── theme.js → Prism theme loader
215
+ └── test/
216
+ └── index.js → Tests
217
+ ```
218
+
219
+ ### How It Fits in the Monorepo
220
+
221
+ This is a **core functionality package** for screenshot capture:
222
+
223
+ | Consumer | Purpose |
224
+ |----------|---------|
225
+ | `browserless` (core) | Provides the `.screenshot()` method |
226
+ | `@browserless/cli` | Powers the `browserless screenshot` command |
227
+ | `@browserless/pdf` | Uses `isWhiteScreenshot` for content detection |
228
+
229
+ ### Dependencies
230
+
231
+ | Package | Purpose |
232
+ |---------|---------|
233
+ | `@browserless/goto` | Page navigation with ad blocking |
234
+ | `sharp` | Image composition for overlays |
235
+ | `jimp` | White/blank screenshot detection |
236
+ | `prism-themes` | Syntax highlighting themes |
237
+ | `svg-gradient` | Generate gradient backgrounds |
238
+ | `got` | Fetch remote background images |
239
+ | `is-html-content` | Detect if content is HTML vs code |
240
+
20
241
  ## License
21
242
 
22
243
  **@browserless/screenshot** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/browserless/blob/master/LICENSE.md) License.<br>
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@browserless/screenshot",
3
- "description": "Take a clean screenshot of any website",
3
+ "description": "Capture high-quality screenshots of websites with overlay support, device emulation, and automated image optimization.",
4
4
  "homepage": "https://browserless.js.org/#/?id=screenshoturl-options",
5
- "version": "10.9.17",
5
+ "version": "10.9.18",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -18,17 +18,21 @@
18
18
  "url": "https://github.com/microlinkhq/browserless/issues"
19
19
  },
20
20
  "keywords": [
21
- "browser",
22
21
  "browserless",
23
- "chrome",
24
- "chromeless",
25
- "core",
22
+ "screenshot",
26
23
  "headless",
24
+ "chrome",
27
25
  "puppeteer",
28
- "screenshot"
26
+ "automation",
27
+ "web-capture",
28
+ "image",
29
+ "overlay",
30
+ "device-emulation",
31
+ "png",
32
+ "jpeg"
29
33
  ],
30
34
  "dependencies": {
31
- "@browserless/goto": "^10.9.16",
35
+ "@browserless/goto": "^10.9.18",
32
36
  "@kikobeats/content-type": "~1.0.3",
33
37
  "@kikobeats/time-span": "~1.0.11",
34
38
  "debug-logfmt": "~1.4.7",
@@ -36,6 +40,7 @@
36
40
  "is-html-content": "~1.0.0",
37
41
  "is-url-http": "~2.3.13",
38
42
  "jimp": "~1.6.0",
43
+ "lodash": "~4.17.23",
39
44
  "map-values-deep": "~1.0.2",
40
45
  "mime": "~3.0.0",
41
46
  "null-prototype-object": "~1.2.5",
@@ -46,7 +51,7 @@
46
51
  "svg-gradient": "~1.0.4"
47
52
  },
48
53
  "devDependencies": {
49
- "@browserless/test": "^10.9.16",
54
+ "@browserless/test": "^10.9.18",
50
55
  "ava": "5",
51
56
  "cheerio": "latest"
52
57
  },
@@ -67,5 +72,5 @@
67
72
  "timeout": "2m",
68
73
  "workerThreads": false
69
74
  },
70
- "gitHead": "9a7d4769776621dc6cf886698591924049530bb6"
75
+ "gitHead": "f5e8cd0788e4bad3b3ad9b007943754f96653817"
71
76
  }