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: reload should not resolve early on fragment navigations #12119

Merged
merged 1 commit into from
Mar 21, 2024
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
4 changes: 4 additions & 0 deletions packages/puppeteer-core/src/api/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export interface WaitForOptions {
* @defaultValue `'load'`
*/
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
/**
* @internal
*/
ignoreSameDocumentNavigation?: boolean;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/puppeteer-core/src/cdp/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class CdpFrame extends Frame {
options: {
timeout?: number;
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
ignoreSameDocumentNavigation?: boolean;
} = {}
): Promise<HTTPResponse | null> {
const {
Expand All @@ -220,7 +221,9 @@ export class CdpFrame extends Frame {
);
const error = await Deferred.race([
watcher.terminationPromise(),
watcher.sameDocumentNavigationPromise(),
...(options.ignoreSameDocumentNavigation
? []
: [watcher.sameDocumentNavigationPromise()]),
watcher.newDocumentNavigationPromise(),
]);
try {
Expand Down
5 changes: 4 additions & 1 deletion packages/puppeteer-core/src/cdp/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,10 @@ export class CdpPage extends Page {
options?: WaitForOptions
): Promise<HTTPResponse | null> {
const [result] = await Promise.all([
this.waitForNavigation(options),
this.waitForNavigation({
...options,
ignoreSameDocumentNavigation: true,
}),
this.#primaryTargetClient.send('Page.reload'),
]);

Expand Down
21 changes: 21 additions & 0 deletions test/src/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ describe('navigation', function () {
const response = await page.goto(server.PREFIX + '/grid.html');
expect(response!.status()).toBe(200);
});
it('should work when reload causes history API in beforeunload', async () => {
const {page, server} = await getTestState();

await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => {
window.addEventListener(
'beforeunload',
() => {
return history.replaceState(null, 'initial', window.location.href);
},
false
);
});
await page.reload();
// Evaluate still works.
expect(
await page.evaluate(() => {
return 1;
})
).toBe(1);
});
it('should navigate to empty page with networkidle0', async () => {
const {page, server} = await getTestState();

Expand Down