cherry-pick(#21322): fix(firefox): fix reload with hash URLs

Fixes #21145
This commit is contained in:
Andrey Lushnikov 2023-03-01 18:56:30 -08:00 committed by Andrey Lushnikov
parent d7ad0a0180
commit b9f4f2cdd3
2 changed files with 21 additions and 1 deletions

View file

@ -393,8 +393,21 @@ export class FFPage implements PageDelegate {
}
async reload(): Promise<void> {
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> {
const { success } = await this._session.send('Page.goBack', { frameId: this._page.mainFrame()._id });

View file

@ -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);