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.
Files changed (44) hide show
  1. package/README.md +93 -8
  2. package/dist/chromium/index.d.ts +3 -0
  3. package/dist/chromium/index.js +7 -1
  4. package/dist/chromium/index.js.map +1 -1
  5. package/dist/chromium/interfaces/screenshot.types.d.ts +10 -0
  6. package/dist/chromium/interfaces/screenshot.types.js +3 -0
  7. package/dist/chromium/interfaces/screenshot.types.js.map +1 -0
  8. package/dist/chromium/screenshots/html.screenshot.d.ts +54 -0
  9. package/dist/chromium/screenshots/html.screenshot.js +67 -0
  10. package/dist/chromium/screenshots/html.screenshot.js.map +1 -0
  11. package/dist/chromium/screenshots/markdown.screenshot.d.ts +52 -0
  12. package/dist/chromium/screenshots/markdown.screenshot.js +66 -0
  13. package/dist/chromium/screenshots/markdown.screenshot.js.map +1 -0
  14. package/dist/chromium/screenshots/screenshot.d.ts +18 -0
  15. package/dist/chromium/screenshots/screenshot.js +21 -0
  16. package/dist/chromium/screenshots/screenshot.js.map +1 -0
  17. package/dist/chromium/screenshots/url.screenshot.d.ts +50 -0
  18. package/dist/chromium/screenshots/url.screenshot.js +66 -0
  19. package/dist/chromium/screenshots/url.screenshot.js.map +1 -0
  20. package/dist/chromium/utils/screenshot.utils.d.ts +22 -0
  21. package/dist/chromium/utils/screenshot.utils.js +75 -0
  22. package/dist/chromium/utils/screenshot.utils.js.map +1 -0
  23. package/dist/main.config.d.ts +5 -0
  24. package/dist/main.config.js +5 -0
  25. package/dist/main.config.js.map +1 -1
  26. package/dist/main.d.ts +1 -1
  27. package/dist/main.js +4 -1
  28. package/dist/main.js.map +1 -1
  29. package/package.json +4 -4
  30. package/src/chromium/index.ts +3 -0
  31. package/src/chromium/interfaces/screenshot.types.ts +12 -0
  32. package/src/chromium/screenshots/html.screenshot.ts +100 -0
  33. package/src/chromium/screenshots/markdown.screenshot.ts +95 -0
  34. package/src/chromium/screenshots/screenshot.ts +22 -0
  35. package/src/chromium/screenshots/tests/html.screenshot.test.ts +192 -0
  36. package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +176 -0
  37. package/src/chromium/screenshots/tests/url.screenshot.test.ts +166 -0
  38. package/src/chromium/screenshots/url.screenshot.ts +91 -0
  39. package/src/chromium/utils/screenshot.utils.ts +115 -0
  40. package/src/chromium/utils/tests/converter.utils.test.ts +13 -1
  41. package/src/chromium/utils/tests/screenshot.utils.test.ts +284 -0
  42. package/src/common/tests/gotenberg.utils.test.ts +46 -0
  43. package/src/main.config.ts +6 -0
  44. package/src/main.ts +8 -1
@@ -0,0 +1,176 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { createReadStream, promises } from 'fs';
3
+
4
+ import FormData from 'form-data';
5
+ import fetch from 'node-fetch';
6
+
7
+ import { MarkdownScreenshot } from '../markdown.screenshot';
8
+
9
+ const { Response } = jest.requireActual('node-fetch');
10
+ jest.mock('node-fetch', () => jest.fn());
11
+
12
+ describe('MarkdownScreenshot', () => {
13
+ const screenshot = new MarkdownScreenshot();
14
+
15
+ describe('endpoint', () => {
16
+ it('should route to Chromium Markdown route', () => {
17
+ expect(screenshot.endpoint).toEqual(
18
+ 'http://localhost:3000/forms/chromium/screenshot/markdown'
19
+ );
20
+ });
21
+ });
22
+
23
+ describe('capture', () => {
24
+ const mockPromisesAccess = jest.spyOn(promises, 'access');
25
+ const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
26
+ const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
27
+
28
+ beforeEach(() => {
29
+ (createReadStream as jest.Mock) = jest.fn();
30
+ });
31
+
32
+ afterEach(() => {
33
+ jest.resetAllMocks();
34
+ });
35
+
36
+ describe('when html and markdown parameters are passed', () => {
37
+ it('should return a buffer', async () => {
38
+ mockFetch.mockResolvedValue(new Response('content'));
39
+ const buffer = await screenshot.capture({
40
+ html: Buffer.from('data'),
41
+ markdown: Buffer.from('markdown')
42
+ });
43
+ expect(buffer).toEqual(Buffer.from('content'));
44
+ });
45
+ });
46
+
47
+ describe('when image properties parameter is passed', () => {
48
+ it('should return a buffer', async () => {
49
+ mockFetch.mockResolvedValue(new Response('content'));
50
+ const buffer = await screenshot.capture({
51
+ html: Buffer.from('data'),
52
+ markdown: Buffer.from('markdown'),
53
+ properties: { format: 'jpeg', quality: 50 }
54
+ });
55
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
56
+ expect(buffer).toEqual(Buffer.from('content'));
57
+ });
58
+ });
59
+
60
+ describe('when header parameter is passed', () => {
61
+ it('should return a buffer', async () => {
62
+ mockFetch.mockResolvedValue(new Response('content'));
63
+ const buffer = await screenshot.capture({
64
+ html: Buffer.from('data'),
65
+ markdown: Buffer.from('markdown'),
66
+ header: Buffer.from('header')
67
+ });
68
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
69
+ expect(buffer).toEqual(Buffer.from('content'));
70
+ });
71
+ });
72
+
73
+ describe('when footer parameter is passed', () => {
74
+ it('should return a buffer', async () => {
75
+ mockFetch.mockResolvedValue(new Response('content'));
76
+ const buffer = await screenshot.capture({
77
+ html: Buffer.from('data'),
78
+ markdown: Buffer.from('markdown'),
79
+ footer: Buffer.from('footer')
80
+ });
81
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
82
+ expect(buffer).toEqual(Buffer.from('content'));
83
+ });
84
+ });
85
+
86
+ describe('when emulatedMediaType parameter is passed', () => {
87
+ it('should return a buffer', async () => {
88
+ mockFetch.mockResolvedValue(new Response('content'));
89
+ const buffer = await screenshot.capture({
90
+ html: Buffer.from('data'),
91
+ markdown: Buffer.from('markdown'),
92
+ emulatedMediaType: 'screen'
93
+ });
94
+
95
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
96
+ expect(buffer).toEqual(Buffer.from('content'));
97
+ });
98
+ });
99
+
100
+ describe('when failOnHttpStatusCodes parameter is passed', () => {
101
+ it('should return a buffer', async () => {
102
+ mockFetch.mockResolvedValue(new Response('content'));
103
+ const buffer = await screenshot.capture({
104
+ html: Buffer.from('data'),
105
+ markdown: Buffer.from('markdown'),
106
+ failOnHttpStatusCodes: [499, 599]
107
+ });
108
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
109
+ expect(buffer).toEqual(Buffer.from('content'));
110
+ });
111
+ });
112
+
113
+ describe('when skipNetworkIdleEvent parameter is passed', () => {
114
+ it('should return a buffer', async () => {
115
+ mockFetch.mockResolvedValue(new Response('content'));
116
+ const buffer = await screenshot.capture({
117
+ html: Buffer.from('data'),
118
+ markdown: Buffer.from('markdown'),
119
+ skipNetworkIdleEvent: true
120
+ });
121
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
122
+ expect(buffer).toEqual(Buffer.from('content'));
123
+ });
124
+ });
125
+
126
+ describe('when all parameters are passed', () => {
127
+ it('should return a buffer', async () => {
128
+ mockFetch.mockResolvedValue(new Response('content'));
129
+ const buffer = await screenshot.capture({
130
+ html: Buffer.from('data'),
131
+ markdown: Buffer.from('markdown'),
132
+ header: Buffer.from('header'),
133
+ footer: Buffer.from('footer'),
134
+ emulatedMediaType: 'screen',
135
+ failOnHttpStatusCodes: [499, 599],
136
+ skipNetworkIdleEvent: true,
137
+ failOnConsoleExceptions: true,
138
+ properties: { format: 'jpeg', quality: 50 },
139
+ optimizeForSpeed: true
140
+ });
141
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(11);
142
+ expect(buffer).toEqual(Buffer.from('content'));
143
+ });
144
+ });
145
+
146
+ describe('when file does not exist', () => {
147
+ it('should throw an error', async () => {
148
+ const errorMessage =
149
+ "ENOENT: no such file or directory, access 'path/to/index.html'";
150
+ mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
151
+
152
+ await expect(() =>
153
+ screenshot.capture({
154
+ html: 'path/to/index.html',
155
+ markdown: 'path/to/file.md'
156
+ })
157
+ ).rejects.toThrow(errorMessage);
158
+ });
159
+ });
160
+
161
+ describe('when fetch request fails', () => {
162
+ it('should throw an error', async () => {
163
+ const errorMessage =
164
+ 'FetchError: request to http://localhost:3000/forms/chromium/screenshot/html failed';
165
+ mockPromisesAccess.mockResolvedValue();
166
+ mockFetch.mockRejectedValue(new Error(errorMessage));
167
+ await expect(() =>
168
+ screenshot.capture({
169
+ html: 'path/to/index.html',
170
+ markdown: 'path/to/file.md'
171
+ })
172
+ ).rejects.toThrow(errorMessage);
173
+ });
174
+ });
175
+ });
176
+ });
@@ -0,0 +1,166 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { createReadStream } from 'fs';
3
+ import FormData from 'form-data';
4
+ import fetch from 'node-fetch';
5
+
6
+ import { UrlScreenshot } from './../url.screenshot';
7
+
8
+ const { Response } = jest.requireActual('node-fetch');
9
+ jest.mock('node-fetch', () => jest.fn());
10
+
11
+ describe('URLScreenshot', () => {
12
+ const screenshot = new UrlScreenshot();
13
+
14
+ describe('endpoint', () => {
15
+ it('should route to Chromium HTML route', () => {
16
+ expect(screenshot.endpoint).toEqual(
17
+ 'http://localhost:3000/forms/chromium/screenshot/url'
18
+ );
19
+ });
20
+ });
21
+
22
+ describe('capture', () => {
23
+ const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
24
+ const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
25
+
26
+ beforeEach(() => {
27
+ (createReadStream as jest.Mock) = jest.fn();
28
+ });
29
+
30
+ afterEach(() => {
31
+ jest.resetAllMocks();
32
+ });
33
+
34
+ describe('when URL is valid', () => {
35
+ it('should return a buffer', async () => {
36
+ mockFetch.mockResolvedValueOnce(new Response('content'));
37
+ const buffer = await screenshot.capture({
38
+ url: 'http://www.example.com/'
39
+ });
40
+ expect(buffer).toEqual(Buffer.from('content'));
41
+ });
42
+ });
43
+
44
+ describe('when header parameter is passed', () => {
45
+ it('should return a buffer', async () => {
46
+ mockFetch.mockResolvedValueOnce(new Response('content'));
47
+ const buffer = await screenshot.capture({
48
+ url: 'http://www.example.com/',
49
+ header: Buffer.from('header')
50
+ });
51
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
52
+ expect(buffer).toEqual(Buffer.from('content'));
53
+ });
54
+ });
55
+
56
+ describe('when footer parameter is passed', () => {
57
+ it('should return a buffer', async () => {
58
+ mockFetch.mockResolvedValueOnce(new Response('content'));
59
+ const buffer = await screenshot.capture({
60
+ url: 'http://www.example.com/',
61
+ footer: Buffer.from('footer')
62
+ });
63
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
64
+ expect(buffer).toEqual(Buffer.from('content'));
65
+ });
66
+ });
67
+
68
+ describe('when image properties parameter is passed', () => {
69
+ it('should return a buffer', async () => {
70
+ mockFetch.mockResolvedValueOnce(new Response('content'));
71
+ const buffer = await screenshot.capture({
72
+ url: 'http://www.example.com/',
73
+ properties: { format: 'jpeg', quality: 50 }
74
+ });
75
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
76
+ expect(buffer).toEqual(Buffer.from('content'));
77
+ });
78
+ });
79
+
80
+ describe('when emulatedMediaType parameter is passed', () => {
81
+ it('should return a buffer', async () => {
82
+ mockFetch.mockResolvedValue(new Response('content'));
83
+ const buffer = await screenshot.capture({
84
+ url: 'http://www.example.com/',
85
+ emulatedMediaType: 'screen'
86
+ });
87
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
88
+ expect(buffer).toEqual(Buffer.from('content'));
89
+ });
90
+ });
91
+
92
+ describe('when failOnHttpStatusCodes parameter is passed', () => {
93
+ it('should return a buffer', async () => {
94
+ mockFetch.mockResolvedValue(new Response('content'));
95
+ const buffer = await screenshot.capture({
96
+ url: 'http://www.example.com/',
97
+ failOnHttpStatusCodes: [499, 599]
98
+ });
99
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
100
+ expect(buffer).toEqual(Buffer.from('content'));
101
+ });
102
+ });
103
+
104
+ describe('when skipNetworkIdleEvent parameter is passed', () => {
105
+ it('should return a buffer', async () => {
106
+ mockFetch.mockResolvedValue(new Response('content'));
107
+ const buffer = await screenshot.capture({
108
+ url: 'http://www.example.com/',
109
+ skipNetworkIdleEvent: true
110
+ });
111
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
112
+ expect(buffer).toEqual(Buffer.from('content'));
113
+ });
114
+ });
115
+
116
+ describe('when optimizeForSpeed parameter is passed', () => {
117
+ it('should return a buffer', async () => {
118
+ mockFetch.mockResolvedValue(new Response('content'));
119
+ const buffer = await screenshot.capture({
120
+ url: 'http://www.example.com/',
121
+ optimizeForSpeed: true
122
+ });
123
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
124
+ expect(buffer).toEqual(Buffer.from('content'));
125
+ });
126
+ });
127
+
128
+ describe('when all parameters are passed', () => {
129
+ it('should return a buffer', async () => {
130
+ mockFetch.mockResolvedValue(new Response('content'));
131
+ const buffer = await screenshot.capture({
132
+ url: 'http://www.example.com/',
133
+ header: Buffer.from('header'),
134
+ footer: Buffer.from('footer'),
135
+ emulatedMediaType: 'screen',
136
+ failOnHttpStatusCodes: [499, 599],
137
+ skipNetworkIdleEvent: true,
138
+ failOnConsoleExceptions: true,
139
+ properties: { format: 'jpeg', quality: 50 },
140
+ optimizeForSpeed: true
141
+ });
142
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(10);
143
+ expect(buffer).toEqual(Buffer.from('content'));
144
+ });
145
+ });
146
+
147
+ describe('when URL is invalid', () => {
148
+ it('should throw an error', async () => {
149
+ await expect(() =>
150
+ screenshot.capture({ url: 'invalid url' })
151
+ ).rejects.toThrow('Invalid URL');
152
+ });
153
+ });
154
+
155
+ describe('when fetch request fails', () => {
156
+ it('should throw an error', async () => {
157
+ const errorMessage =
158
+ 'FetchError: request to http://localhost:3000/forms/chromium/convert/html failed';
159
+ mockFetch.mockRejectedValueOnce(new Error(errorMessage));
160
+ await expect(() =>
161
+ screenshot.capture({ url: 'http://www.example.com/' })
162
+ ).rejects.toThrow(errorMessage);
163
+ });
164
+ });
165
+ });
166
+ });
@@ -0,0 +1,91 @@
1
+ import { URL } from 'url';
2
+ import FormData from 'form-data';
3
+ import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
4
+ import { ImageProperties } from '../interfaces/screenshot.types';
5
+ import { ScreenshotUtils } from '../utils/screenshot.utils';
6
+ import { Screenshot } from './screenshot';
7
+ import { ChromiumRoute } from '../../main.config';
8
+ import { EmulatedMediaType } from '../interfaces/common.types';
9
+
10
+ /**
11
+ * Class representing a URL screenshot that extends the base screenshot class.
12
+ * This class is used to screenshot a URL using Gotenberg service.
13
+ *
14
+ * @extends Screenshot
15
+ */
16
+ export class UrlScreenshot extends Screenshot {
17
+ /**
18
+ * Creates an instance of UrlScreenshot.
19
+ * Initializes the screenshot with the URL screenshot route.
20
+ */
21
+ constructor() {
22
+ super(ChromiumRoute.URL);
23
+ }
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
+ async capture({
44
+ url,
45
+ header,
46
+ footer,
47
+ properties,
48
+ emulatedMediaType,
49
+ waitDelay,
50
+ waitForExpression,
51
+ extraHttpHeaders,
52
+ failOnHttpStatusCodes,
53
+ failOnConsoleExceptions,
54
+ skipNetworkIdleEvent,
55
+ optimizeForSpeed
56
+ }: {
57
+ url: string;
58
+ header?: PathLikeOrReadStream;
59
+ footer?: PathLikeOrReadStream;
60
+ properties?: ImageProperties;
61
+ emulatedMediaType?: EmulatedMediaType;
62
+ waitDelay?: string;
63
+ waitForExpression?: string;
64
+ extraHttpHeaders?: Record<string, string>;
65
+ failOnHttpStatusCodes?: number[];
66
+ failOnConsoleExceptions?: boolean;
67
+ skipNetworkIdleEvent?: boolean;
68
+ optimizeForSpeed?: boolean;
69
+ }): Promise<Buffer> {
70
+ const _url = new URL(url);
71
+ const data = new FormData();
72
+
73
+ data.append('url', _url.href);
74
+
75
+ await ScreenshotUtils.customize(data, {
76
+ header,
77
+ footer,
78
+ properties,
79
+ emulatedMediaType,
80
+ waitDelay,
81
+ waitForExpression,
82
+ extraHttpHeaders,
83
+ failOnHttpStatusCodes,
84
+ failOnConsoleExceptions,
85
+ skipNetworkIdleEvent,
86
+ optimizeForSpeed
87
+ });
88
+
89
+ return GotenbergUtils.fetch(this.endpoint, data);
90
+ }
91
+ }
@@ -0,0 +1,115 @@
1
+ import {
2
+ ImageProperties,
3
+ ScreenshotOptions
4
+ } from './../interfaces/screenshot.types';
5
+ import FormData from 'form-data';
6
+
7
+ import { GotenbergUtils } from '../../common';
8
+
9
+ /**
10
+ * Utility class for handling common tasks related to screenshot.
11
+ */
12
+ export class ScreenshotUtils {
13
+ /**
14
+ * Adds page properties to the FormData object based on the provided imageProperties.
15
+ *
16
+ * @param {FormData} data - The FormData object to which page properties will be added.
17
+ * @param {ImageProperties} imageProperties - The page properties to be added to the FormData.
18
+ */
19
+ public static addImageProperties(
20
+ data: FormData,
21
+ imageProperties: ImageProperties
22
+ ): void {
23
+ data.append('format', imageProperties.format);
24
+
25
+ if (imageProperties.quality) {
26
+ GotenbergUtils.assert(
27
+ imageProperties.format === 'jpeg',
28
+ 'Compression quality is exclusively supported for JPEG format.'
29
+ );
30
+ GotenbergUtils.assert(
31
+ imageProperties.quality >= 0 && imageProperties.quality <= 100,
32
+ 'Invalid compression quality. Please provide a value between 0 and 100.'
33
+ );
34
+
35
+ data.append('quality', imageProperties.quality);
36
+ }
37
+
38
+ if (imageProperties.omitBackground) {
39
+ data.append(
40
+ 'omitBackground',
41
+ String(imageProperties.omitBackground)
42
+ );
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Customizes the FormData object based on the provided screenshot options.
48
+ *
49
+ * @param {FormData} data - The FormData object to be customized.
50
+ * @param {ScreenshotOptions} options - The screenshot options to apply to the FormData.
51
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
52
+ */
53
+ public static async customize(
54
+ data: FormData,
55
+ options: ScreenshotOptions
56
+ ): Promise<void> {
57
+ if (options.header) {
58
+ const { header } = options;
59
+ await GotenbergUtils.addFile(data, header, 'header.html');
60
+ }
61
+
62
+ if (options.footer) {
63
+ const { footer } = options;
64
+ await GotenbergUtils.addFile(data, footer, 'footer.html');
65
+ }
66
+
67
+ if (options.emulatedMediaType) {
68
+ data.append('emulatedMediaType', options.emulatedMediaType);
69
+ }
70
+
71
+ if (options.properties) {
72
+ ScreenshotUtils.addImageProperties(data, options.properties);
73
+ }
74
+
75
+ if (options.waitDelay) {
76
+ data.append('waitDelay', options.waitDelay);
77
+ }
78
+
79
+ if (options.waitForExpression) {
80
+ data.append('waitForExpression', options.waitForExpression);
81
+ }
82
+
83
+ if (options.extraHttpHeaders) {
84
+ data.append(
85
+ 'extraHttpHeaders',
86
+ JSON.stringify(options.extraHttpHeaders)
87
+ );
88
+ }
89
+
90
+ if (options.failOnHttpStatusCodes) {
91
+ data.append(
92
+ 'failOnHttpStatusCodes',
93
+ JSON.stringify(options.failOnHttpStatusCodes)
94
+ );
95
+ }
96
+
97
+ if (options.failOnConsoleExceptions) {
98
+ data.append(
99
+ 'failOnConsoleExceptions',
100
+ String(options.failOnConsoleExceptions)
101
+ );
102
+ }
103
+
104
+ if (options.skipNetworkIdleEvent) {
105
+ data.append(
106
+ 'skipNetworkIdleEvent',
107
+ String(options.skipNetworkIdleEvent)
108
+ );
109
+ }
110
+
111
+ if (options.optimizeForSpeed) {
112
+ data.append('optimizeForSpeed', String(options.optimizeForSpeed));
113
+ }
114
+ }
115
+ }
@@ -365,9 +365,11 @@ describe('GotenbergUtils', () => {
365
365
  userAgent:
366
366
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
367
367
  extraHttpHeaders: { 'X-Custom-Header': 'value' },
368
+ failOnHttpStatusCodes: [499, 599],
369
+ skipNetworkIdleEvent: true,
368
370
  failOnConsoleExceptions: true
369
371
  });
370
- expect(mockFormDataAppend).toHaveBeenCalledTimes(12);
372
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(14);
371
373
  expect(data.append).toHaveBeenNthCalledWith(
372
374
  1,
373
375
  'pdfa',
@@ -423,9 +425,19 @@ describe('GotenbergUtils', () => {
423
425
  );
424
426
  expect(data.append).toHaveBeenNthCalledWith(
425
427
  12,
428
+ 'failOnHttpStatusCodes',
429
+ JSON.stringify([499, 599])
430
+ );
431
+ expect(data.append).toHaveBeenNthCalledWith(
432
+ 13,
426
433
  'failOnConsoleExceptions',
427
434
  'true'
428
435
  );
436
+ expect(data.append).toHaveBeenNthCalledWith(
437
+ 14,
438
+ 'skipNetworkIdleEvent',
439
+ 'true'
440
+ );
429
441
  });
430
442
  });
431
443
  });