fix: disable memory cache when intercepting in webkit (#28458)

This commit is contained in:
Yury Semikhatsky 2023-12-01 14:49:27 -08:00 committed by GitHub
parent f44ef81af7
commit b166189247
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -185,6 +185,7 @@ export class WKPage implements PageDelegate {
];
if (this._page.needsRequestInterception()) {
promises.push(session.send('Network.setInterceptionEnabled', { enabled: true }));
promises.push(session.send('Network.setResourceCachingDisabled', { disabled: true }));
promises.push(session.send('Network.addInterception', { url: '.*', stage: 'request', isRegex: true }));
}
if (this._page._browserContext.isSettingStorageState()) {
@ -723,6 +724,7 @@ export class WKPage implements PageDelegate {
const enabled = this._page.needsRequestInterception();
await Promise.all([
this._updateState('Network.setInterceptionEnabled', { enabled }),
this._updateState('Network.setResourceCachingDisabled', { disabled: enabled }),
this._updateState('Network.addInterception', { url: '.*', stage: 'request', isRegex: true }),
]);
}

View file

@ -172,3 +172,21 @@ it('should not break remote worker importScripts', async ({ page, server, browse
await page.goto(server.PREFIX + '/worker/worker-http-import.html');
await page.waitForSelector("#status:has-text('finished')");
});
it('should disable memory cache when intercepting', async ({ page, server }) => {
let interceted = 0;
await page.route('**/page.html', route => {
++interceted;
void route.fulfill({
body: 'success'
});
});
await page.goto(server.PREFIX + '/page.html');
expect(await page.locator('body').textContent()).toContain('success');
await page.goto(server.EMPTY_PAGE);
await expect(page).toHaveURL(server.EMPTY_PAGE);
expect(interceted).toBe(1);
await page.goBack();
await expect(page).toHaveURL(server.PREFIX + '/page.html');
expect(interceted).toBe(2);
});