Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
3 changes: 1 addition & 2 deletions tests/page/page-history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down