mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: reload should not resolve early on fragment navigations (#12119)
This commit is contained in:
parent
b096ffaa03
commit
d4760317c9
@ -63,6 +63,10 @@ export interface WaitForOptions {
|
||||
* @defaultValue `'load'`
|
||||
*/
|
||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
ignoreSameDocumentNavigation?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,6 +206,7 @@ export class CdpFrame extends Frame {
|
||||
options: {
|
||||
timeout?: number;
|
||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
||||
ignoreSameDocumentNavigation?: boolean;
|
||||
} = {}
|
||||
): Promise<HTTPResponse | null> {
|
||||
const {
|
||||
@ -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 {
|
||||
|
@ -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'),
|
||||
]);
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user