chromiumly 2.7.0 → 2.8.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/README.md +93 -8
- package/dist/chromium/index.d.ts +3 -0
- package/dist/chromium/index.js +7 -1
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/screenshot.types.d.ts +10 -0
- package/dist/chromium/interfaces/screenshot.types.js +3 -0
- package/dist/chromium/interfaces/screenshot.types.js.map +1 -0
- package/dist/chromium/screenshots/html.screenshot.d.ts +54 -0
- package/dist/chromium/screenshots/html.screenshot.js +67 -0
- package/dist/chromium/screenshots/html.screenshot.js.map +1 -0
- package/dist/chromium/screenshots/markdown.screenshot.d.ts +52 -0
- package/dist/chromium/screenshots/markdown.screenshot.js +66 -0
- package/dist/chromium/screenshots/markdown.screenshot.js.map +1 -0
- package/dist/chromium/screenshots/screenshot.d.ts +18 -0
- package/dist/chromium/screenshots/screenshot.js +21 -0
- package/dist/chromium/screenshots/screenshot.js.map +1 -0
- package/dist/chromium/screenshots/url.screenshot.d.ts +50 -0
- package/dist/chromium/screenshots/url.screenshot.js +66 -0
- package/dist/chromium/screenshots/url.screenshot.js.map +1 -0
- package/dist/chromium/utils/screenshot.utils.d.ts +22 -0
- package/dist/chromium/utils/screenshot.utils.js +75 -0
- package/dist/chromium/utils/screenshot.utils.js.map +1 -0
- package/dist/main.config.d.ts +5 -0
- package/dist/main.config.js +5 -0
- package/dist/main.config.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +4 -1
- package/dist/main.js.map +1 -1
- package/package.json +4 -4
- package/src/chromium/index.ts +3 -0
- package/src/chromium/interfaces/screenshot.types.ts +12 -0
- package/src/chromium/screenshots/html.screenshot.ts +100 -0
- package/src/chromium/screenshots/markdown.screenshot.ts +95 -0
- package/src/chromium/screenshots/screenshot.ts +22 -0
- package/src/chromium/screenshots/tests/html.screenshot.test.ts +192 -0
- package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +176 -0
- package/src/chromium/screenshots/tests/url.screenshot.test.ts +166 -0
- package/src/chromium/screenshots/url.screenshot.ts +91 -0
- package/src/chromium/utils/screenshot.utils.ts +115 -0
- package/src/chromium/utils/tests/converter.utils.test.ts +13 -1
- package/src/chromium/utils/tests/screenshot.utils.test.ts +284 -0
- package/src/common/tests/gotenberg.utils.test.ts +46 -0
- package/src/main.config.ts +6 -0
- package/src/main.ts +8 -1
package/README.md
CHANGED
|
@@ -11,6 +11,29 @@
|
|
|
11
11
|
A lightweight Typescript library that interacts with [Gotenberg](https://gotenberg.dev/)'s different modules to convert
|
|
12
12
|
a variety of document formats to PDF files.
|
|
13
13
|
|
|
14
|
+
# Table of Contents
|
|
15
|
+
|
|
16
|
+
1. [Introduction](#introduction)
|
|
17
|
+
- [Install](#install)
|
|
18
|
+
- [Prerequisites](#prerequisites)
|
|
19
|
+
- [Get Started](#get-started)
|
|
20
|
+
2. [Configuration](#configuration)
|
|
21
|
+
- [dotenv](#dotenv)
|
|
22
|
+
- [config](#config)
|
|
23
|
+
3. [Modules](#modules)
|
|
24
|
+
- [Chromium](#chromium)
|
|
25
|
+
- [URL](#url)
|
|
26
|
+
- [HTML](#html)
|
|
27
|
+
- [Markdown](#markdown)
|
|
28
|
+
- [Customization](#customization)
|
|
29
|
+
- [Conversion](#conversion)
|
|
30
|
+
- [Screenshot](#screenshot)
|
|
31
|
+
- [PDF Engine](#pdf-engine)
|
|
32
|
+
- [convert](#convert)
|
|
33
|
+
- [merge](#merge)
|
|
34
|
+
- [generate](#generate)
|
|
35
|
+
4. [Snippet](#snippet)
|
|
36
|
+
|
|
14
37
|
## Install
|
|
15
38
|
|
|
16
39
|
Using npm:
|
|
@@ -62,16 +85,18 @@ GOTENBERG_ENDPOINT=http://localhost:3000
|
|
|
62
85
|
## Modules
|
|
63
86
|
|
|
64
87
|
Chromiumly introduces different classes that serve as wrappers to
|
|
65
|
-
Gotenberg's [
|
|
88
|
+
Gotenberg's [routes](https://gotenberg.dev/docs/routes). These classes encompass methods featuring an
|
|
66
89
|
input file parameter, such as `html`, `header`, `footer`, and `markdown`, capable of accepting inputs in the form of a
|
|
67
90
|
`string` (i.e. file path), `Buffer`, or `ReadStream`.
|
|
68
91
|
|
|
69
92
|
### Chormium
|
|
70
93
|
|
|
71
94
|
There are three different classes that come with a single method (i.e.`convert`) which calls one of
|
|
72
|
-
Chromium's [routes](https://gotenberg.dev/docs/
|
|
95
|
+
Chromium's [Conversion routes](https://gotenberg.dev/docs/routes#convert-with-chromium) to convert `html` and `markdown` files, or
|
|
73
96
|
a `url` to a `buffer` which contains the converted PDF file content.
|
|
74
97
|
|
|
98
|
+
Similarly, a new set of classes have been added to harness the recently introduced Gotenberg [Screenshot routes](https://gotenberg.dev/docs/routes#screenshots-route). These classes include a single method called `capture`, which allows capturing full-page screenshots of `html`, `markdown`, and `url`.
|
|
99
|
+
|
|
75
100
|
#### URL
|
|
76
101
|
|
|
77
102
|
```typescript
|
|
@@ -83,6 +108,15 @@ const buffer = await urlConverter.convert({
|
|
|
83
108
|
});
|
|
84
109
|
```
|
|
85
110
|
|
|
111
|
+
```typescript
|
|
112
|
+
import { UrlScreenshot } from "chromiumly";
|
|
113
|
+
|
|
114
|
+
const screenshot = new UrlScreenshot();
|
|
115
|
+
const buffer = await screenshot.capture({
|
|
116
|
+
url: "https://www.example.com/",
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
86
120
|
#### HTML
|
|
87
121
|
|
|
88
122
|
The only requirement is that the file name should be `index.html`.
|
|
@@ -96,6 +130,15 @@ const buffer = await htmlConverter.convert({
|
|
|
96
130
|
});
|
|
97
131
|
```
|
|
98
132
|
|
|
133
|
+
```typescript
|
|
134
|
+
import { HtmlScreenshot } from "chromiumly";
|
|
135
|
+
|
|
136
|
+
const screenshot = new HtmlScreenshot();
|
|
137
|
+
const buffer = await screenshot.capture({
|
|
138
|
+
html: "path/to/index.html",
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
99
142
|
#### Markdown
|
|
100
143
|
|
|
101
144
|
This route accepts an `index.html` file plus a markdown file.
|
|
@@ -110,8 +153,20 @@ const buffer = await markdownConverter.convert({
|
|
|
110
153
|
});
|
|
111
154
|
```
|
|
112
155
|
|
|
156
|
+
```typescript
|
|
157
|
+
import { MarkdownScreenshot } from "chromiumly";
|
|
158
|
+
|
|
159
|
+
const screenshot = new MarkdownScreenshot();
|
|
160
|
+
const buffer = await screenshot.capture({
|
|
161
|
+
html: "path/to/index.html",
|
|
162
|
+
markdown: "path/to/file.md",
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
113
166
|
### Customization
|
|
114
167
|
|
|
168
|
+
#### Conversion
|
|
169
|
+
|
|
115
170
|
`convert()` method takes an optional `properties` parameter of the following type which dictates how the PDF generated
|
|
116
171
|
file will look like.
|
|
117
172
|
|
|
@@ -157,17 +212,47 @@ type ConversionOptions = {
|
|
|
157
212
|
};
|
|
158
213
|
```
|
|
159
214
|
|
|
215
|
+
#### Screenshot
|
|
216
|
+
|
|
217
|
+
Similarly, the `capture()` method takes an optional `properties` parameter of the specified type, influencing the appearance of the captured screenshot file.
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
type ImageProperties = {
|
|
221
|
+
format: "png" | "jpeg" | "webp"; //The image compression format, either "png", "jpeg" or "webp".
|
|
222
|
+
quality?: number; // The compression quality from range 0 to 100 (jpeg only).
|
|
223
|
+
omitBackground?: boolean; // Hide the default white background and allow generating screenshots with transparency.
|
|
224
|
+
};
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Furthermore, alongside the customization options offered by `ImageProperties`, the `capture()` method accommodates a variety of parameters to expand the versatility of the screenshot process. Below is a comprehensive overview of all parameters available:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
type ScreenshotOptions = {
|
|
231
|
+
properties?: ImageProperties;
|
|
232
|
+
header?: PathLikeOrReadStream;
|
|
233
|
+
footer?: PathLikeOrReadStream;
|
|
234
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
235
|
+
waitDelay?: string; // Duration (e.g, '5s') to wait when loading an HTML document before convertion.
|
|
236
|
+
waitForExpression?: string; // JavaScript's expression to wait before converting an HTML document into PDF until it returns true.
|
|
237
|
+
extraHttpHeaders?: Record<string, string>;
|
|
238
|
+
failOnHttpStatusCodes?: number[]; // Return a 409 Conflict response if the HTTP status code is in the list (default [499,599])
|
|
239
|
+
failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false)
|
|
240
|
+
skipNetworkIdleEvent?: boolean; // Do not wait for Chromium network to be idle (default false)
|
|
241
|
+
optimizeForSpeed?: boolean; // Define whether to optimize image encoding for speed, not for resulting size.
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
160
245
|
### PDF Engine
|
|
161
246
|
|
|
162
|
-
The `PDFEngine` combines the functionality of
|
|
163
|
-
Gotenberg's [PDF Engines](https://gotenberg.dev/docs/
|
|
164
|
-
and [LibreOffice](https://gotenberg.dev/docs/
|
|
247
|
+
The `PDFEngine` combines the functionality of
|
|
248
|
+
Gotenberg's [PDF Engines](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route)
|
|
249
|
+
and [LibreOffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) modules to manipulate different file formats.
|
|
165
250
|
|
|
166
251
|
#### convert
|
|
167
252
|
|
|
168
|
-
This method interacts with [LibreOffice](https://gotenberg.dev/docs/
|
|
253
|
+
This method interacts with [LibreOffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) module to convert different
|
|
169
254
|
documents to PDF files. You can find the file extensions
|
|
170
|
-
accepted [here](https://gotenberg.dev/docs/
|
|
255
|
+
accepted [here](https://gotenberg.dev/docs/routes#convert-with-libreoffice#route).
|
|
171
256
|
|
|
172
257
|
```typescript
|
|
173
258
|
import { PDFEngine } from "chromiumly";
|
|
@@ -185,7 +270,7 @@ Similarly to Chromium's module `convert` method, this method takes the following
|
|
|
185
270
|
|
|
186
271
|
#### merge
|
|
187
272
|
|
|
188
|
-
This method interacts with [PDF Engines](https://gotenberg.dev/docs/
|
|
273
|
+
This method interacts with [PDF Engines](https://gotenberg.dev/docs/routes#merge-pdfs-route) module which gathers different
|
|
189
274
|
engines that can manipulate and merge PDF files such
|
|
190
275
|
as: [PDFtk](https://gitlab.com/pdftk-java/pdftk), [PDFcpu](https://github.com/pdfcpu/pdfcpu), [QPDF](https://github.com/qpdf/qpdf),
|
|
191
276
|
and [UNO](https://github.com/unoconv/unoconv).
|
package/dist/chromium/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { UrlScreenshot } from './screenshots/url.screenshot';
|
|
2
|
+
export { MarkdownScreenshot } from './screenshots/markdown.screenshot';
|
|
3
|
+
export { HtmlScreenshot } from './screenshots/html.screenshot';
|
|
1
4
|
export { HtmlConverter } from './converters/html.converter';
|
|
2
5
|
export { MarkdownConverter } from './converters/markdown.converter';
|
|
3
6
|
export { UrlConverter } from './converters/url.converter';
|
package/dist/chromium/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UrlConverter = exports.MarkdownConverter = exports.HtmlConverter = void 0;
|
|
3
|
+
exports.UrlConverter = exports.MarkdownConverter = exports.HtmlConverter = exports.HtmlScreenshot = exports.MarkdownScreenshot = exports.UrlScreenshot = void 0;
|
|
4
|
+
var url_screenshot_1 = require("./screenshots/url.screenshot");
|
|
5
|
+
Object.defineProperty(exports, "UrlScreenshot", { enumerable: true, get: function () { return url_screenshot_1.UrlScreenshot; } });
|
|
6
|
+
var markdown_screenshot_1 = require("./screenshots/markdown.screenshot");
|
|
7
|
+
Object.defineProperty(exports, "MarkdownScreenshot", { enumerable: true, get: function () { return markdown_screenshot_1.MarkdownScreenshot; } });
|
|
8
|
+
var html_screenshot_1 = require("./screenshots/html.screenshot");
|
|
9
|
+
Object.defineProperty(exports, "HtmlScreenshot", { enumerable: true, get: function () { return html_screenshot_1.HtmlScreenshot; } });
|
|
4
10
|
var html_converter_1 = require("./converters/html.converter");
|
|
5
11
|
Object.defineProperty(exports, "HtmlConverter", { enumerable: true, get: function () { return html_converter_1.HtmlConverter; } });
|
|
6
12
|
var markdown_converter_1 = require("./converters/markdown.converter");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chromium/index.ts"],"names":[],"mappings":";;;AAAA,8DAA4D;AAAnD,+GAAA,aAAa,OAAA;AACtB,sEAAoE;AAA3D,uHAAA,iBAAiB,OAAA;AAC1B,4DAA0D;AAAjD,6GAAA,YAAY,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chromium/index.ts"],"names":[],"mappings":";;;AAAA,+DAA6D;AAApD,+GAAA,aAAa,OAAA;AACtB,yEAAuE;AAA9D,yHAAA,kBAAkB,OAAA;AAC3B,iEAA+D;AAAtD,iHAAA,cAAc,OAAA;AACvB,8DAA4D;AAAnD,+GAAA,aAAa,OAAA;AACtB,sEAAoE;AAA3D,uHAAA,iBAAiB,OAAA;AAC1B,4DAA0D;AAAjD,6GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChromiumOptions } from './common.types';
|
|
2
|
+
export type ImageProperties = {
|
|
3
|
+
format: 'png' | 'jpeg' | 'webp';
|
|
4
|
+
quality?: number;
|
|
5
|
+
omitBackground?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ScreenshotOptions = ChromiumOptions & {
|
|
8
|
+
properties?: ImageProperties;
|
|
9
|
+
optimizeForSpeed?: boolean;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.types.js","sourceRoot":"","sources":["../../../src/chromium/interfaces/screenshot.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
4
|
+
import { Screenshot } from './screenshot';
|
|
5
|
+
import { ImageProperties } from '../interfaces/screenshot.types';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing an HTML Screenshot that extends the base Screenshot class.
|
|
8
|
+
* This class is used to screenshot HTML content using Gotenberg service.
|
|
9
|
+
*
|
|
10
|
+
* @extends Screenshot
|
|
11
|
+
*/
|
|
12
|
+
export declare class HtmlScreenshot extends Screenshot {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of HtmlScreenshot.
|
|
15
|
+
* Initializes the Screenshot with the HTML screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Screenshots HTML content.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Screenshot options.
|
|
22
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
23
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
24
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
25
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
26
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
27
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
28
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
29
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
30
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
31
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
32
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
33
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
34
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
35
|
+
*/
|
|
36
|
+
capture({ html, assets, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnConsoleExceptions, failOnHttpStatusCodes, skipNetworkIdleEvent, optimizeForSpeed }: {
|
|
37
|
+
html: PathLikeOrReadStream;
|
|
38
|
+
assets?: {
|
|
39
|
+
file: PathLikeOrReadStream;
|
|
40
|
+
name: string;
|
|
41
|
+
}[];
|
|
42
|
+
header?: PathLikeOrReadStream;
|
|
43
|
+
footer?: PathLikeOrReadStream;
|
|
44
|
+
properties?: ImageProperties;
|
|
45
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
46
|
+
waitDelay?: string;
|
|
47
|
+
waitForExpression?: string;
|
|
48
|
+
extraHttpHeaders?: Record<string, string>;
|
|
49
|
+
failOnConsoleExceptions?: boolean;
|
|
50
|
+
failOnHttpStatusCodes?: number[];
|
|
51
|
+
skipNetworkIdleEvent?: boolean;
|
|
52
|
+
optimizeForSpeed?: boolean;
|
|
53
|
+
}): Promise<Buffer>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HtmlScreenshot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
6
|
+
const common_1 = require("../../common");
|
|
7
|
+
const main_config_1 = require("../../main.config");
|
|
8
|
+
const screenshot_utils_1 = require("../utils/screenshot.utils");
|
|
9
|
+
const screenshot_1 = require("./screenshot");
|
|
10
|
+
/**
|
|
11
|
+
* Class representing an HTML Screenshot that extends the base Screenshot class.
|
|
12
|
+
* This class is used to screenshot HTML content using Gotenberg service.
|
|
13
|
+
*
|
|
14
|
+
* @extends Screenshot
|
|
15
|
+
*/
|
|
16
|
+
class HtmlScreenshot extends screenshot_1.Screenshot {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of HtmlScreenshot.
|
|
19
|
+
* Initializes the Screenshot with the HTML screenshot route.
|
|
20
|
+
*/
|
|
21
|
+
constructor() {
|
|
22
|
+
super(main_config_1.ChromiumRoute.HTML);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Screenshots HTML content.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options - Screenshot options.
|
|
28
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
29
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
30
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
31
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
32
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
33
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
34
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
35
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
36
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
37
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
38
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
39
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
40
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
41
|
+
*/
|
|
42
|
+
capture({ html, assets, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnConsoleExceptions, failOnHttpStatusCodes, skipNetworkIdleEvent, optimizeForSpeed }) {
|
|
43
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const data = new form_data_1.default();
|
|
45
|
+
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
46
|
+
if (assets === null || assets === void 0 ? void 0 : assets.length) {
|
|
47
|
+
yield Promise.all(assets.map(({ file, name }) => common_1.GotenbergUtils.addFile(data, file, name)));
|
|
48
|
+
}
|
|
49
|
+
yield screenshot_utils_1.ScreenshotUtils.customize(data, {
|
|
50
|
+
header,
|
|
51
|
+
footer,
|
|
52
|
+
properties,
|
|
53
|
+
emulatedMediaType,
|
|
54
|
+
waitDelay,
|
|
55
|
+
waitForExpression,
|
|
56
|
+
extraHttpHeaders,
|
|
57
|
+
failOnHttpStatusCodes,
|
|
58
|
+
failOnConsoleExceptions,
|
|
59
|
+
skipNetworkIdleEvent,
|
|
60
|
+
optimizeForSpeed
|
|
61
|
+
});
|
|
62
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.HtmlScreenshot = HtmlScreenshot;
|
|
67
|
+
//# sourceMappingURL=html.screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/html.screenshot.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAAoE;AACpE,mDAAkD;AAElD,gEAA4D;AAC5D,6CAA0C;AAG1C;;;;;GAKG;AACH,MAAa,cAAe,SAAQ,uBAAU;IAC1C;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,EACV,IAAI,EACJ,MAAM,EACN,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAenB;;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;YAEvD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,CAAC;gBACjB,MAAM,OAAO,CAAC,GAAG,CACb,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAC1B,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAC3C,CACJ,CAAC;YACN,CAAC;YAED,MAAM,kCAAe,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;gBACpB,gBAAgB;aACnB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AApFD,wCAoFC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { ImageProperties } from '../interfaces/screenshot.types';
|
|
4
|
+
import { Screenshot } from './screenshot';
|
|
5
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a Markdown screenshot that extends the base Screenshot class.
|
|
8
|
+
* This class is used to screenshots HTML with markdown content using Gotenberg service.
|
|
9
|
+
*
|
|
10
|
+
* @extends Screenshot
|
|
11
|
+
*/
|
|
12
|
+
export declare class MarkdownScreenshot extends Screenshot {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of MarkdownScreenshot.
|
|
15
|
+
* Initializes the Screenshot with the Markdown screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Screenshots HTML with markdown.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Screenshot options.
|
|
22
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
23
|
+
* @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be screenshoted.
|
|
24
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
25
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
26
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
27
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
28
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
29
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
30
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
31
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
32
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
33
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
34
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
35
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
36
|
+
*/
|
|
37
|
+
capture({ html, markdown, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }: {
|
|
38
|
+
html: PathLikeOrReadStream;
|
|
39
|
+
markdown: PathLikeOrReadStream;
|
|
40
|
+
header?: PathLikeOrReadStream;
|
|
41
|
+
footer?: PathLikeOrReadStream;
|
|
42
|
+
properties?: ImageProperties;
|
|
43
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
44
|
+
waitDelay?: string;
|
|
45
|
+
waitForExpression?: string;
|
|
46
|
+
extraHttpHeaders?: Record<string, string>;
|
|
47
|
+
failOnHttpStatusCodes?: number[];
|
|
48
|
+
failOnConsoleExceptions?: boolean;
|
|
49
|
+
skipNetworkIdleEvent?: boolean;
|
|
50
|
+
optimizeForSpeed?: boolean;
|
|
51
|
+
}): Promise<Buffer>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MarkdownScreenshot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
6
|
+
const common_1 = require("../../common");
|
|
7
|
+
const screenshot_utils_1 = require("../utils/screenshot.utils");
|
|
8
|
+
const screenshot_1 = require("./screenshot");
|
|
9
|
+
const main_config_1 = require("../../main.config");
|
|
10
|
+
/**
|
|
11
|
+
* Class representing a Markdown screenshot that extends the base Screenshot class.
|
|
12
|
+
* This class is used to screenshots HTML with markdown content using Gotenberg service.
|
|
13
|
+
*
|
|
14
|
+
* @extends Screenshot
|
|
15
|
+
*/
|
|
16
|
+
class MarkdownScreenshot extends screenshot_1.Screenshot {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of MarkdownScreenshot.
|
|
19
|
+
* Initializes the Screenshot with the Markdown screenshot route.
|
|
20
|
+
*/
|
|
21
|
+
constructor() {
|
|
22
|
+
super(main_config_1.ChromiumRoute.MARKDOWN);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Screenshots HTML with markdown.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options - Screenshot options.
|
|
28
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
29
|
+
* @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be screenshoted.
|
|
30
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
31
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
32
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
33
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
34
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
35
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
36
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
37
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
38
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
39
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
40
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
41
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
42
|
+
*/
|
|
43
|
+
capture({ html, markdown, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }) {
|
|
44
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const data = new form_data_1.default();
|
|
46
|
+
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
47
|
+
yield common_1.GotenbergUtils.addFile(data, markdown, 'file.md');
|
|
48
|
+
yield screenshot_utils_1.ScreenshotUtils.customize(data, {
|
|
49
|
+
header,
|
|
50
|
+
footer,
|
|
51
|
+
properties,
|
|
52
|
+
emulatedMediaType,
|
|
53
|
+
waitDelay,
|
|
54
|
+
waitForExpression,
|
|
55
|
+
extraHttpHeaders,
|
|
56
|
+
failOnHttpStatusCodes,
|
|
57
|
+
failOnConsoleExceptions,
|
|
58
|
+
skipNetworkIdleEvent,
|
|
59
|
+
optimizeForSpeed
|
|
60
|
+
});
|
|
61
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MarkdownScreenshot = MarkdownScreenshot;
|
|
66
|
+
//# sourceMappingURL=markdown.screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/markdown.screenshot.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAAoE;AAEpE,gEAA4D;AAC5D,6CAA0C;AAC1C,mDAAkD;AAGlD;;;;;GAKG;AACH,MAAa,kBAAmB,SAAQ,uBAAU;IAC9C;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACG,OAAO,CAAC,EACV,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAenB;;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;YAEvD,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;YAExD,MAAM,kCAAe,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;gBACpB,gBAAgB;aACnB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AA/ED,gDA+EC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ChromiumRoute } from '../../main.config';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract class representing a generic screenshot.
|
|
4
|
+
* Concrete screenshot classes should extend this class and implement specific screenshot logic.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class Screenshot {
|
|
7
|
+
/**
|
|
8
|
+
* The endpoint URL for the screenshot.
|
|
9
|
+
*/
|
|
10
|
+
readonly endpoint: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the screenshot class.
|
|
13
|
+
* Initializes the endpoint URL based on the provided ChromiumRoute.
|
|
14
|
+
*
|
|
15
|
+
* @param {ChromiumRoute} route - The ChromiumRoute enum value representing the screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor(route: ChromiumRoute);
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Screenshot = void 0;
|
|
4
|
+
const main_config_1 = require("../../main.config");
|
|
5
|
+
/**
|
|
6
|
+
* Abstract class representing a generic screenshot.
|
|
7
|
+
* Concrete screenshot classes should extend this class and implement specific screenshot logic.
|
|
8
|
+
*/
|
|
9
|
+
class Screenshot {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of the screenshot class.
|
|
12
|
+
* Initializes the endpoint URL based on the provided ChromiumRoute.
|
|
13
|
+
*
|
|
14
|
+
* @param {ChromiumRoute} route - The ChromiumRoute enum value representing the screenshot route.
|
|
15
|
+
*/
|
|
16
|
+
constructor(route) {
|
|
17
|
+
this.endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.CHROMIUM_SCREENSHOT_PATH}/${main_config_1.Chromiumly.CHROMIUM_ROUTES[route]}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Screenshot = Screenshot;
|
|
21
|
+
//# sourceMappingURL=screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/screenshot.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAE9D;;;GAGG;AACH,MAAsB,UAAU;IAM5B;;;;;OAKG;IACH,YAAY,KAAoB;QAC5B,IAAI,CAAC,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,wBAAwB,IAAI,wBAAU,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IACnI,CAAC;CACJ;AAfD,gCAeC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { ImageProperties } from '../interfaces/screenshot.types';
|
|
4
|
+
import { Screenshot } from './screenshot';
|
|
5
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a URL screenshot that extends the base screenshot class.
|
|
8
|
+
* This class is used to screenshot a URL using Gotenberg service.
|
|
9
|
+
*
|
|
10
|
+
* @extends Screenshot
|
|
11
|
+
*/
|
|
12
|
+
export declare class UrlScreenshot extends Screenshot {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of UrlScreenshot.
|
|
15
|
+
* Initializes the screenshot with the URL screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Screenshots URL.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Screenshot options.
|
|
22
|
+
* @param {string} options.url - The URL of the content to be screenshoted
|
|
23
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
24
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
25
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
26
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
27
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
28
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
29
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
30
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
31
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
32
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
33
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
34
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
35
|
+
*/
|
|
36
|
+
capture({ url, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }: {
|
|
37
|
+
url: string;
|
|
38
|
+
header?: PathLikeOrReadStream;
|
|
39
|
+
footer?: PathLikeOrReadStream;
|
|
40
|
+
properties?: ImageProperties;
|
|
41
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
42
|
+
waitDelay?: string;
|
|
43
|
+
waitForExpression?: string;
|
|
44
|
+
extraHttpHeaders?: Record<string, string>;
|
|
45
|
+
failOnHttpStatusCodes?: number[];
|
|
46
|
+
failOnConsoleExceptions?: boolean;
|
|
47
|
+
skipNetworkIdleEvent?: boolean;
|
|
48
|
+
optimizeForSpeed?: boolean;
|
|
49
|
+
}): Promise<Buffer>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UrlScreenshot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const url_1 = require("url");
|
|
6
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
7
|
+
const common_1 = require("../../common");
|
|
8
|
+
const screenshot_utils_1 = require("../utils/screenshot.utils");
|
|
9
|
+
const screenshot_1 = require("./screenshot");
|
|
10
|
+
const main_config_1 = require("../../main.config");
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a URL screenshot that extends the base screenshot class.
|
|
13
|
+
* This class is used to screenshot a URL using Gotenberg service.
|
|
14
|
+
*
|
|
15
|
+
* @extends Screenshot
|
|
16
|
+
*/
|
|
17
|
+
class UrlScreenshot extends screenshot_1.Screenshot {
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of UrlScreenshot.
|
|
20
|
+
* Initializes the screenshot with the URL screenshot route.
|
|
21
|
+
*/
|
|
22
|
+
constructor() {
|
|
23
|
+
super(main_config_1.ChromiumRoute.URL);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Screenshots URL.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} options - Screenshot options.
|
|
29
|
+
* @param {string} options.url - The URL of the content to be screenshoted
|
|
30
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
31
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
32
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
33
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
34
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
35
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
36
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
37
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
38
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
39
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
40
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
41
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
42
|
+
*/
|
|
43
|
+
capture({ url, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }) {
|
|
44
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const _url = new url_1.URL(url);
|
|
46
|
+
const data = new form_data_1.default();
|
|
47
|
+
data.append('url', _url.href);
|
|
48
|
+
yield screenshot_utils_1.ScreenshotUtils.customize(data, {
|
|
49
|
+
header,
|
|
50
|
+
footer,
|
|
51
|
+
properties,
|
|
52
|
+
emulatedMediaType,
|
|
53
|
+
waitDelay,
|
|
54
|
+
waitForExpression,
|
|
55
|
+
extraHttpHeaders,
|
|
56
|
+
failOnHttpStatusCodes,
|
|
57
|
+
failOnConsoleExceptions,
|
|
58
|
+
skipNetworkIdleEvent,
|
|
59
|
+
optimizeForSpeed
|
|
60
|
+
});
|
|
61
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.UrlScreenshot = UrlScreenshot;
|
|
66
|
+
//# sourceMappingURL=url.screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/url.screenshot.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAC1B,kEAAiC;AACjC,yCAAoE;AAEpE,gEAA4D;AAC5D,6CAA0C;AAC1C,mDAAkD;AAGlD;;;;;GAKG;AACH,MAAa,aAAc,SAAQ,uBAAU;IACzC;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,EACV,GAAG,EACH,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAcnB;;YACG,MAAM,IAAI,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAE9B,MAAM,kCAAe,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;gBACpB,gBAAgB;aACnB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AA3ED,sCA2EC"}
|