fix(pause): revert timeouts after pause (#23578)

Fixes #23523.
This commit is contained in:
Dmitry Gozman 2023-06-07 12:30:10 -07:00 committed by GitHub
parent eda109388e
commit 4f8680f7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 2 deletions

View File

@ -203,14 +203,14 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
await bindingCall.call(func);
}
setDefaultNavigationTimeout(timeout: number) {
setDefaultNavigationTimeout(timeout: number | undefined) {
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
this._wrapApiCall(async () => {
this._channel.setDefaultNavigationTimeoutNoReply({ timeout }).catch(() => {});
}, true);
}
setDefaultTimeout(timeout: number) {
setDefaultTimeout(timeout: number | undefined) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._wrapApiCall(async () => {
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(() => {});

View File

@ -681,10 +681,14 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
async pause() {
if (require('inspector').url())
return;
const defaultNavigationTimeout = this._browserContext._timeoutSettings.defaultNavigationTimeout();
const defaultTimeout = this._browserContext._timeoutSettings.defaultTimeout();
this._browserContext.setDefaultNavigationTimeout(0);
this._browserContext.setDefaultTimeout(0);
this._instrumentation?.onWillPause();
await this._closedOrCrashedRace.safeRace(this.context()._channel.pause());
this._browserContext.setDefaultNavigationTimeout(defaultNavigationTimeout);
this._browserContext.setDefaultTimeout(defaultTimeout);
}
async pdf(options: PDFOptions = {}): Promise<Buffer> {

View File

@ -37,6 +37,14 @@ export class TimeoutSettings {
this._defaultNavigationTimeout = timeout;
}
defaultNavigationTimeout() {
return this._defaultNavigationTimeout;
}
defaultTimeout() {
return this._defaultTimeout;
}
navigationTimeout(options: { timeout?: number }): number {
if (typeof options.timeout === 'number')
return options.timeout;

View File

@ -30,6 +30,20 @@ it('should resume when closing inspector', async ({ page, recorderPageGetter, cl
await scriptPromise;
});
it('should not reset timeouts', async ({ page, recorderPageGetter, closeRecorder, server }) => {
page.context().setDefaultNavigationTimeout(1000);
page.context().setDefaultTimeout(1000);
const pausePromise = page.pause();
await recorderPageGetter();
await closeRecorder();
await pausePromise;
server.setRoute('/empty.html', () => {});
const error = await page.goto(server.EMPTY_PAGE).catch(e => e);
expect(error.message).toContain('page.goto: Timeout 1000ms exceeded.');
});
it.describe('pause', () => {
it.skip(({ mode }) => mode !== 'default');