From 25af050bd4bb8581c5898c25a8d033824bbaf7d2 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 5 Dec 2019 09:32:52 -0700 Subject: [PATCH] feat(webkit): add page back/forward commands (#144) --- src/webkit/Page.ts | 18 ++++++++++++++++++ test/navigation.spec.js | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/webkit/Page.ts b/src/webkit/Page.ts index 2540d7122f..2b0d142b08 100644 --- a/src/webkit/Page.ts +++ b/src/webkit/Page.ts @@ -267,6 +267,24 @@ export class Page extends EventEmitter { return response; } + async goBack(): Promise { + return await this._go('Page.goBack'); + } + + async goForward(): Promise { + return await this._go('Page.goForward'); + } + + async _go(command: T): Promise { + const [response, error] = await Promise.all([ + this.waitForNavigation(), + this._session.send(command).then(() => null).catch(e => e), + ]); + if (error) + return null; + return response; + } + async waitForNavigation(): Promise { return await this._frameManager.mainFrame().waitForNavigation(); } diff --git a/test/navigation.spec.js b/test/navigation.spec.js index 5af9c269c8..44ee32d46c 100644 --- a/test/navigation.spec.js +++ b/test/navigation.spec.js @@ -466,7 +466,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME response = await page.goForward(); expect(response).toBe(null); }); - it.skip(WEBKIT)('should work with HistoryAPI', async({page, server}) => { + it('should work with HistoryAPI', async({page, server}) => { await page.goto(server.EMPTY_PAGE); await page.evaluate(() => { history.pushState({}, '', '/first.html');