From f539afa2a710eef20d00209cb8a437df253a7efc Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 13 Dec 2019 22:46:27 -0700 Subject: [PATCH] feat(webkit): support ignoreHTTPSErrors launcher option (#243) Also roll webkit to 1036 --- package.json | 2 +- src/webkit/Browser.ts | 14 +++++++++++++- src/webkit/Launcher.ts | 6 ++++-- test/ignorehttpserrors.spec.js | 6 +++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 0c941e9f58..59a02a40ce 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "playwright": { "chromium_revision": "724623", "firefox_revision": "1005", - "webkit_revision": "1032" + "webkit_revision": "1036" }, "scripts": { "unit": "node test/test.js", diff --git a/src/webkit/Browser.ts b/src/webkit/Browser.ts index c4af04008a..2dea19cc41 100644 --- a/src/webkit/Browser.ts +++ b/src/webkit/Browser.ts @@ -37,16 +37,19 @@ export class Browser extends EventEmitter implements BrowserInterface { _targets = new Map(); private _eventListeners: RegisteredListener[]; private _privateEvents = new EventEmitter(); + private readonly _ignoreHTTPSErrors: boolean; constructor( connection: Connection, + ignoreHTTPSErrors: boolean, defaultViewport: types.Viewport | null, process: childProcess.ChildProcess | null, closeCallback?: (() => Promise)) { super(); + this._connection = connection; + this._ignoreHTTPSErrors = ignoreHTTPSErrors; this._defaultViewport = defaultViewport; this._process = process; - this._connection = connection; this._closeCallback = closeCallback || (() => Promise.resolve()); /** @type {!Map} */ @@ -67,6 +70,9 @@ export class Browser extends EventEmitter implements BrowserInterface { debugError(e); throw e; }); + + if (this._ignoreHTTPSErrors) + this._setIgnoreTLSFailures(undefined); } async userAgent(): Promise { @@ -88,6 +94,8 @@ export class Browser extends EventEmitter implements BrowserInterface { async newContext(): Promise { const {browserContextId} = await this._connection.send('Browser.createContext'); + if (this._ignoreHTTPSErrors) + await this._setIgnoreTLSFailures(browserContextId); const context = this._createBrowserContext(browserContextId); this._contexts.set(browserContextId, context); return context; @@ -250,6 +258,10 @@ export class Browser extends EventEmitter implements BrowserInterface { }, this, isIncognito); return context; } + + async _setIgnoreTLSFailures(browserContextId: string | undefined) { + await this._connection.send('Browser.setIgnoreCertificateErrors', { browserContextId, ignore: true }); + } } const BrowserEvents = { diff --git a/src/webkit/Launcher.ts b/src/webkit/Launcher.ts index 226cb89adc..7f520bb6f8 100644 --- a/src/webkit/Launcher.ts +++ b/src/webkit/Launcher.ts @@ -59,7 +59,8 @@ export class Launcher { handleSIGTERM = true, handleSIGHUP = true, defaultViewport = {width: 800, height: 600}, - slowMo = 0 + slowMo = 0, + ignoreHTTPSErrors = false } = options; const webkitArguments = []; @@ -103,7 +104,7 @@ export class Launcher { try { const transport = new PipeTransport(launched.process.stdio[3] as NodeJS.WritableStream, launched.process.stdio[4] as NodeJS.ReadableStream); connection = new Connection(transport, slowMo); - const browser = new Browser(connection, defaultViewport, launched.process, launched.gracefullyClose); + const browser = new Browser(connection, ignoreHTTPSErrors, defaultViewport, launched.process, launched.gracefullyClose); await browser._waitForTarget(t => t._type === 'page'); return browser; } catch (e) { @@ -137,6 +138,7 @@ export type LauncherLaunchOptions = { env?: {[key: string]: string} | undefined, defaultViewport?: types.Viewport | null, slowMo?: number, + ignoreHTTPSErrors?: boolean, }; let cachedMacVersion = undefined; diff --git a/test/ignorehttpserrors.spec.js b/test/ignorehttpserrors.spec.js index d929de2ab3..1c5e82247f 100644 --- a/test/ignorehttpserrors.spec.js +++ b/test/ignorehttpserrors.spec.js @@ -19,7 +19,7 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p const {describe, xdescribe, fdescribe} = testRunner; const {it, fit, xit} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; - describe.skip(WEBKIT)('ignoreHTTPSErrors', function() { + describe('ignoreHTTPSErrors', function() { beforeAll(async state => { state.browser = await playwright.launch({...defaultBrowserOptions, ignoreHTTPSErrors: true}); }); @@ -43,13 +43,13 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p expect(error).toBe(null); expect(response.ok()).toBe(true); }); - it('should work with request interception', async({page, server, httpsServer}) => { + it.skip(WEBKIT)('should work with request interception', async({page, server, httpsServer}) => { await page.interception.enable(); page.on('request', request => page.interception.continue(request)); const response = await page.goto(httpsServer.EMPTY_PAGE); expect(response.status()).toBe(200); }); - it('should work with mixed content', async({page, server, httpsServer}) => { + it.skip(WEBKIT)('should work with mixed content', async({page, server, httpsServer}) => { httpsServer.setRoute('/mixedcontent.html', (req, res) => { res.end(``); });