diff --git a/src/chromium/converters/html.converter.ts b/src/chromium/converters/html.converter.ts index c023f481..d257f5ef 100644 --- a/src/chromium/converters/html.converter.ts +++ b/src/chromium/converters/html.converter.ts @@ -59,6 +59,8 @@ export class HtmlConverter extends Converter { extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, + failOnResourceHttpStatusCodes, + failOnResourceLoadingFailed, skipNetworkIdleEvent, metadata, cookies, @@ -89,6 +91,8 @@ export class HtmlConverter extends Converter { extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, + failOnResourceHttpStatusCodes, + failOnResourceLoadingFailed, skipNetworkIdleEvent, metadata, cookies, diff --git a/src/chromium/converters/markdown.converter.ts b/src/chromium/converters/markdown.converter.ts index 1576350f..708d5df1 100644 --- a/src/chromium/converters/markdown.converter.ts +++ b/src/chromium/converters/markdown.converter.ts @@ -60,6 +60,8 @@ export class MarkdownConverter extends Converter { extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, + failOnResourceHttpStatusCodes, + failOnResourceLoadingFailed, skipNetworkIdleEvent, metadata, cookies, @@ -87,7 +89,9 @@ export class MarkdownConverter extends Converter { skipNetworkIdleEvent, metadata, cookies, - downloadFrom + downloadFrom, + failOnResourceHttpStatusCodes, + failOnResourceLoadingFailed }); return GotenbergUtils.fetch( diff --git a/src/chromium/converters/url.converter.ts b/src/chromium/converters/url.converter.ts index 70c0844f..bebac95c 100644 --- a/src/chromium/converters/url.converter.ts +++ b/src/chromium/converters/url.converter.ts @@ -57,6 +57,8 @@ export class UrlConverter extends Converter { userAgent, extraHttpHeaders, failOnHttpStatusCodes, + failOnResourceHttpStatusCodes, + failOnResourceLoadingFailed, failOnConsoleExceptions, skipNetworkIdleEvent, metadata, @@ -84,7 +86,9 @@ export class UrlConverter extends Converter { skipNetworkIdleEvent, metadata, cookies, - downloadFrom + downloadFrom, + failOnResourceHttpStatusCodes, + failOnResourceLoadingFailed }); return GotenbergUtils.fetch( diff --git a/src/chromium/interfaces/common.types.ts b/src/chromium/interfaces/common.types.ts index ac264e90..a955702c 100644 --- a/src/chromium/interfaces/common.types.ts +++ b/src/chromium/interfaces/common.types.ts @@ -22,6 +22,8 @@ export type ChromiumOptions = { extraHttpHeaders?: Record; failOnHttpStatusCodes?: number[]; // Return a 409 Conflict response if the HTTP status code is in the list (default [499,599]) failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false) + failOnResourceHttpStatusCodes?: number[]; // Return a 409 Conflict response if the HTTP status code is in the list (default [499,599]) + failOnResourceLoadingFailed?: boolean; // Return a 409 Conflict response if the resource loading failed (default false) skipNetworkIdleEvent?: boolean; // Do not wait for Chromium network to be idle (default false) cookies?: Cookie[]; // Cookies to be written. downloadFrom?: DownloadFrom; // Download a file from a URL. It must return a Content-Disposition header with a filename parameter. diff --git a/src/chromium/utils/converter.utils.ts b/src/chromium/utils/converter.utils.ts index 513f2242..6045826c 100644 --- a/src/chromium/utils/converter.utils.ts +++ b/src/chromium/utils/converter.utils.ts @@ -163,6 +163,20 @@ export class ConverterUtils { ); } + if (options.failOnResourceHttpStatusCodes) { + data.append( + 'failOnResourceHttpStatusCodes', + JSON.stringify(options.failOnResourceHttpStatusCodes) + ); + } + + if (options.failOnResourceLoadingFailed) { + data.append( + 'failOnResourceLoadingFailed', + String(options.failOnResourceLoadingFailed) + ); + } + if (options.failOnConsoleExceptions) { data.append( 'failOnConsoleExceptions', diff --git a/src/chromium/utils/screenshot.utils.ts b/src/chromium/utils/screenshot.utils.ts index 56c8e35b..f31edb1e 100644 --- a/src/chromium/utils/screenshot.utils.ts +++ b/src/chromium/utils/screenshot.utils.ts @@ -96,6 +96,20 @@ export class ScreenshotUtils { ); } + if (options.failOnResourceHttpStatusCodes) { + data.append( + 'failOnResourceHttpStatusCodes', + JSON.stringify(options.failOnResourceHttpStatusCodes) + ); + } + + if (options.failOnResourceLoadingFailed) { + data.append( + 'failOnResourceLoadingFailed', + String(options.failOnResourceLoadingFailed) + ); + } + if (options.failOnConsoleExceptions) { data.append( 'failOnConsoleExceptions', diff --git a/src/chromium/utils/tests/converter.utils.test.ts b/src/chromium/utils/tests/converter.utils.test.ts index 8ce32632..ef6fe2e1 100644 --- a/src/chromium/utils/tests/converter.utils.test.ts +++ b/src/chromium/utils/tests/converter.utils.test.ts @@ -431,6 +431,8 @@ describe('ConverterUtils', () => { 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36', extraHttpHeaders: { 'X-Custom-Header': 'value' }, failOnHttpStatusCodes: [499, 599], + failOnResourceHttpStatusCodes: [499, 599], + failOnResourceLoadingFailed: true, skipNetworkIdleEvent: false, failOnConsoleExceptions: true, metadata: { Author: 'John Doe' }, @@ -439,7 +441,7 @@ describe('ConverterUtils', () => { extraHttpHeaders: { 'Content-Type': 'application/json' } } }); - expect(mockFormDataAppend).toHaveBeenCalledTimes(16); + expect(mockFormDataAppend).toHaveBeenCalledTimes(18); expect(data.append).toHaveBeenNthCalledWith( 1, 'pdfa', @@ -500,21 +502,31 @@ describe('ConverterUtils', () => { ); expect(data.append).toHaveBeenNthCalledWith( 13, + 'failOnResourceHttpStatusCodes', + JSON.stringify([499, 599]) + ); + expect(data.append).toHaveBeenNthCalledWith( + 14, + 'failOnResourceLoadingFailed', + 'true' + ); + expect(data.append).toHaveBeenNthCalledWith( + 15, 'failOnConsoleExceptions', 'true' ); expect(data.append).toHaveBeenNthCalledWith( - 14, + 16, 'skipNetworkIdleEvent', 'false' ); expect(data.append).toHaveBeenNthCalledWith( - 15, + 17, 'metadata', JSON.stringify({ Author: 'John Doe' }) ); expect(data.append).toHaveBeenNthCalledWith( - 16, + 18, 'downloadFrom', JSON.stringify({ url: 'http://example.com', diff --git a/src/chromium/utils/tests/screenshot.utils.test.ts b/src/chromium/utils/tests/screenshot.utils.test.ts index 9e89a08c..3da59613 100644 --- a/src/chromium/utils/tests/screenshot.utils.test.ts +++ b/src/chromium/utils/tests/screenshot.utils.test.ts @@ -251,6 +251,8 @@ describe('ScreenshotUtils', () => { await ScreenshotUtils.customize(data, { emulatedMediaType: 'screen', failOnHttpStatusCodes: [499, 599], + failOnResourceHttpStatusCodes: [499, 599], + failOnResourceLoadingFailed: true, skipNetworkIdleEvent: false, failOnConsoleExceptions: true, properties: { @@ -266,7 +268,7 @@ describe('ScreenshotUtils', () => { extraHttpHeaders: { 'Content-Type': 'application/json' } } }); - expect(mockFormDataAppend).toHaveBeenCalledTimes(11); + expect(mockFormDataAppend).toHaveBeenCalledTimes(13); expect(data.append).toHaveBeenNthCalledWith( 1, 'emulatedMediaType', @@ -300,21 +302,32 @@ describe('ScreenshotUtils', () => { ); expect(data.append).toHaveBeenNthCalledWith( 8, + 'failOnResourceHttpStatusCodes', + JSON.stringify([499, 599]) + ); + expect(data.append).toHaveBeenNthCalledWith( + 9, + 'failOnResourceLoadingFailed', + 'true' + ); + + expect(data.append).toHaveBeenNthCalledWith( + 10, 'failOnConsoleExceptions', 'true' ); expect(data.append).toHaveBeenNthCalledWith( - 9, + 11, 'skipNetworkIdleEvent', 'false' ); expect(data.append).toHaveBeenNthCalledWith( - 10, + 12, 'optimizeForSpeed', 'true' ); expect(data.append).toHaveBeenNthCalledWith( - 11, + 13, 'downloadFrom', JSON.stringify({ url: 'http://example.com',