fix(firefox): fix reload with hash URLs (#21322)

Fixes #21145
This commit is contained in:
Andrey Lushnikov 2023-03-01 18:56:30 -08:00 committed by GitHub
parent e64d0ae556
commit bfc895787f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -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> {

View File

@ -185,9 +185,8 @@ 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, browserName }) => {
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' });
it.fixme(browserName === 'firefox');
await page.goto(server.EMPTY_PAGE + '#hash');
await page.reload();
await expect(page).toHaveURL(server.EMPTY_PAGE + '#hash');