Skip to content

Commit

Permalink
cherry-pick(#21322): fix(firefox): fix reload with hash URLs
Browse files Browse the repository at this point in the history
Fixes #21145
  • Loading branch information
aslushnikov committed Mar 2, 2023
1 parent d7ad0a0 commit b9f4f2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/playwright-core/src/server/firefox/ffPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,20 @@ export class FFPage implements PageDelegate {
}

async reload(): Promise<void> {
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<boolean> {
Expand Down
7 changes: 7 additions & 0 deletions tests/page/page-history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b9f4f2c

Please sign in to comment.