diff --git a/docs/src/api/class-fetchrequest.md b/docs/src/api/class-fetchrequest.md index 3bef765ffd38a..07596a6bb96bb 100644 --- a/docs/src/api/class-fetchrequest.md +++ b/docs/src/api/class-fetchrequest.md @@ -57,6 +57,8 @@ Request timeout in milliseconds. Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes. +### option: FetchRequest.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%% + ## async method: FetchRequest.get - returns: <[FetchResponse]> @@ -89,6 +91,8 @@ Request timeout in milliseconds. Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes. +### option: FetchRequest.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%% + ## async method: FetchRequest.post - returns: <[FetchResponse]> @@ -128,3 +132,5 @@ Request timeout in milliseconds. Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes. + +### option: FetchRequest.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%% diff --git a/src/client/fetch.ts b/src/client/fetch.ts index 09da722c1063c..0ed45ee8fd3f0 100644 --- a/src/client/fetch.ts +++ b/src/client/fetch.ts @@ -35,6 +35,7 @@ export type FetchOptions = { data?: string | Buffer | Serializable, timeout?: number, failOnStatusCode?: boolean, + ignoreHTTPSErrors?: boolean, }; export class FetchRequest extends ChannelOwner implements api.FetchRequest { @@ -59,6 +60,7 @@ export class FetchRequest extends ChannelOwner { return this.fetch(urlOrRequest, { ...options, @@ -74,6 +76,7 @@ export class FetchRequest extends ChannelOwner { return this.fetch(urlOrRequest, { ...options, @@ -129,6 +132,7 @@ export class FetchRequest extends ChannelOwner Validator): Scheme { formData: tOptional(tAny), timeout: tOptional(tNumber), failOnStatusCode: tOptional(tBoolean), + ignoreHTTPSErrors: tOptional(tBoolean), }); scheme.FetchRequestFetchResponseBodyParams = tObject({ fetchUid: tString, diff --git a/src/server/fetch.ts b/src/server/fetch.ts index 471358a7db9cd..f7afbafbde486 100644 --- a/src/server/fetch.ts +++ b/src/server/fetch.ts @@ -123,7 +123,7 @@ export abstract class FetchRequest extends SdkObject { deadline }; // rejectUnauthorized = undefined is treated as true in node 12. - if (defaults.ignoreHTTPSErrors) + if (params.ignoreHTTPSErrors || defaults.ignoreHTTPSErrors) options.rejectUnauthorized = false; const requestUrl = new URL(params.url, defaults.baseURL); diff --git a/src/server/types.ts b/src/server/types.ts index 8789898b5b634..08b7ed80fbd46 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -393,6 +393,7 @@ export type FetchOptions = { formData?: FormField[], timeout?: number, failOnStatusCode?: boolean, + ignoreHTTPSErrors?: boolean, }; export type FetchResponse = { diff --git a/tests/browsercontext-fetch.spec.ts b/tests/browsercontext-fetch.spec.ts index beb6f32d5405b..f44931d03ced6 100644 --- a/tests/browsercontext-fetch.spec.ts +++ b/tests/browsercontext-fetch.spec.ts @@ -157,6 +157,11 @@ for (const method of ['get', 'post', 'fetch']) { }).catch(e => e); expect(error.message).toContain('404 Not Found'); }); + + it(`${method}should support ignoreHTTPSErrors option`, async ({ context, httpsServer }) => { + const response = await context._request[method](httpsServer.EMPTY_PAGE, { ignoreHTTPSErrors: true }); + expect(response.status()).toBe(200); + }); } it('should not add context cookie if cookie header passed as a parameter', async ({ context, server }) => { @@ -517,7 +522,7 @@ it('should support https', async ({ context, httpsServer }) => { } }); -it('should support ignoreHTTPSErrors', async ({ contextFactory, contextOptions, httpsServer }) => { +it('should inherit ignoreHTTPSErrors from context', async ({ contextFactory, contextOptions, httpsServer }) => { const context = await contextFactory({ ...contextOptions, ignoreHTTPSErrors: true }); const response = await context._request.get(httpsServer.EMPTY_PAGE); expect(response.status()).toBe(200); diff --git a/types/types.d.ts b/types/types.d.ts index 85cf211f82fad..a63956eb3fa78 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -12667,6 +12667,11 @@ export interface FetchRequest { */ headers?: { [key: string]: string; }; + /** + * Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. + */ + ignoreHTTPSErrors?: boolean; + /** * If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used. */ @@ -12700,6 +12705,11 @@ export interface FetchRequest { */ headers?: { [key: string]: string; }; + /** + * Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. + */ + ignoreHTTPSErrors?: boolean; + /** * Query parameters to be send with the URL. */ @@ -12738,6 +12748,11 @@ export interface FetchRequest { */ headers?: { [key: string]: string; }; + /** + * Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. + */ + ignoreHTTPSErrors?: boolean; + /** * Query parameters to be send with the URL. */