fix: make page.goBack work with bfcache in tab mode (#10818)
This commit is contained in:
parent
a9446f3d43
commit
22daf1861f
@ -192,7 +192,7 @@ export class FrameManager extends EventEmitter {
|
||||
});
|
||||
session.on('Page.frameNavigated', event => {
|
||||
this.#frameNavigatedReceived.add(event.frame.id);
|
||||
void this.#onFrameNavigated(event.frame);
|
||||
void this.#onFrameNavigated(event.frame, event.type);
|
||||
});
|
||||
session.on('Page.navigatedWithinDocument', event => {
|
||||
this.#onFrameNavigatedWithinDocument(event.frameId, event.url);
|
||||
@ -351,7 +351,7 @@ export class FrameManager extends EventEmitter {
|
||||
);
|
||||
}
|
||||
if (!this.#frameNavigatedReceived.has(frameTree.frame.id)) {
|
||||
void this.#onFrameNavigated(frameTree.frame);
|
||||
void this.#onFrameNavigated(frameTree.frame, 'Navigation');
|
||||
} else {
|
||||
this.#frameNavigatedReceived.delete(frameTree.frame.id);
|
||||
}
|
||||
@ -386,7 +386,10 @@ export class FrameManager extends EventEmitter {
|
||||
this.emit(FrameManagerEmittedEvents.FrameAttached, frame);
|
||||
}
|
||||
|
||||
async #onFrameNavigated(framePayload: Protocol.Page.Frame): Promise<void> {
|
||||
async #onFrameNavigated(
|
||||
framePayload: Protocol.Page.Frame,
|
||||
navigationType: Protocol.Page.NavigationType
|
||||
): Promise<void> {
|
||||
const frameId = framePayload.id;
|
||||
const isMainFrame = !framePayload.parentId;
|
||||
|
||||
@ -415,7 +418,7 @@ export class FrameManager extends EventEmitter {
|
||||
frame = await this._frameTree.waitForFrame(frameId);
|
||||
frame._navigated(framePayload);
|
||||
this.emit(FrameManagerEmittedEvents.FrameNavigated, frame);
|
||||
frame.emit(FrameEmittedEvents.FrameNavigated);
|
||||
frame.emit(FrameEmittedEvents.FrameNavigated, navigationType);
|
||||
}
|
||||
|
||||
async #createIsolatedWorld(session: CDPSession, name: string): Promise<void> {
|
||||
|
@ -14,6 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Protocol from 'devtools-protocol';
|
||||
|
||||
import {HTTPResponse} from '../api/HTTPResponse.js';
|
||||
import {assert} from '../util/assert.js';
|
||||
import {Deferred} from '../util/Deferred.js';
|
||||
@ -218,7 +220,10 @@ export class LifecycleWatcher {
|
||||
this.#checkLifecycleComplete();
|
||||
}
|
||||
|
||||
#navigated(): void {
|
||||
#navigated(navigationType: Protocol.Page.NavigationType): void {
|
||||
if (navigationType === 'BackForwardCacheRestore') {
|
||||
return this.#frameSwapped();
|
||||
}
|
||||
this.#checkLifecycleComplete();
|
||||
}
|
||||
|
||||
|
@ -179,8 +179,10 @@ export class ChromeLauncher extends ProductLauncher {
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-extensions',
|
||||
// AcceptCHFrame disabled because of crbug.com/1348106.
|
||||
'--disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints',
|
||||
...(USE_TAB_TARGET ? [] : ['--disable-features=Prerender2']),
|
||||
'--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints',
|
||||
...(USE_TAB_TARGET
|
||||
? []
|
||||
: ['--disable-features=Prerender2,BackForwardCache']),
|
||||
'--disable-hang-monitor',
|
||||
'--disable-ipc-flooding-protection',
|
||||
'--disable-popup-blocking',
|
||||
|
@ -3899,6 +3899,12 @@
|
||||
"parameters": ["firefox", "headful"],
|
||||
"expectations": ["PASS", "TIMEOUT"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[bfcache.spec] *",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["webDriverBiDi"],
|
||||
"expectations": ["SKIP"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[prerender.spec] Prerender can navigate to a prerendered page via input",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
|
2
test/assets/cached/bfcache/index.html
Normal file
2
test/assets/cached/bfcache/index.html
Normal file
@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html>
|
||||
<body>BFCached<a href="target.html">next</a></body>
|
2
test/assets/cached/bfcache/target.html
Normal file
2
test/assets/cached/bfcache/target.html
Normal file
@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html>
|
||||
<body>target</body>
|
47
test/src/bfcache.spec.ts
Normal file
47
test/src/bfcache.spec.ts
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
import {launch} from './mocha-utils.js';
|
||||
|
||||
describe('BFCache', function () {
|
||||
it('can navigate to a BFCached page', async () => {
|
||||
const {httpsServer, page, close} = await launch({
|
||||
ignoreHTTPSErrors: true,
|
||||
});
|
||||
|
||||
try {
|
||||
page.setDefaultTimeout(2000);
|
||||
|
||||
await page.goto(httpsServer.PREFIX + '/cached/bfcache/index.html');
|
||||
|
||||
await Promise.all([page.waitForNavigation(), page.locator('a').click()]);
|
||||
|
||||
expect(page.url()).toContain('target.html');
|
||||
|
||||
await Promise.all([page.waitForNavigation(), page.goBack()]);
|
||||
|
||||
expect(
|
||||
await page.evaluate(() => {
|
||||
return document.body.innerText;
|
||||
})
|
||||
).toBe('BFCachednext');
|
||||
} finally {
|
||||
await close();
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user