From b9f4f2cdd33d61065d393f62680e32b521fb5367 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 1 Mar 2023 18:56:30 -0800 Subject: [PATCH] cherry-pick(#21322): fix(firefox): fix reload with hash URLs Fixes #21145 --- .../playwright-core/src/server/firefox/ffPage.ts | 15 ++++++++++++++- tests/page/page-history.spec.ts | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.ts index 47be1684d6536..a279f7c4a31cb 100644 --- a/packages/playwright-core/src/server/firefox/ffPage.ts +++ b/packages/playwright-core/src/server/firefox/ffPage.ts @@ -393,7 +393,20 @@ export class FFPage implements PageDelegate { } async reload(): Promise { - await this._session.send('Page.reload'); + const mainFrame = this._page._frameManager.mainFrame(); + // This is a workaround for https://github.com/microsoft/playwright/issues/21145 + let hash = ''; + try { + hash = (new URL(mainFrame.url())).hash; + } catch (e) { + // Ignore URL parsing error, if any. + } + if (hash.length) { + const context = await mainFrame._utilityContext(); + await context.rawEvaluateJSON(`void window.location.reload();`); + } else { + await this._session.send('Page.reload'); + } } async goBack(): Promise { diff --git a/tests/page/page-history.spec.ts b/tests/page/page-history.spec.ts index 58a8bcb48fbb9..f7380ab9ac820 100644 --- a/tests/page/page-history.spec.ts +++ b/tests/page/page-history.spec.ts @@ -185,6 +185,13 @@ it('page.reload should work with cross-origin redirect', async ({ page, server, await expect(page).toHaveURL(server.CROSS_PROCESS_PREFIX + '/title.html'); }); +it('page.reload should work on a page with a hash', async ({ page, server }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21145' }); + await page.goto(server.EMPTY_PAGE + '#hash'); + await page.reload(); + await expect(page).toHaveURL(server.EMPTY_PAGE + '#hash'); +}); + it('page.goBack during renderer-initiated navigation', async ({ page, server }) => { await page.goto(server.PREFIX + '/one-style.html'); await page.goto(server.EMPTY_PAGE);