Skip to content

Commit

Permalink
fix(pause): revert timeouts after pause (#23578)
Browse files Browse the repository at this point in the history
Fixes #23523.
  • Loading branch information
dgozman authored Jun 7, 2023
1 parent eda1093 commit 4f8680f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});
Expand Down
4 changes: 4 additions & 0 deletions packages/playwright-core/src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
8 changes: 8 additions & 0 deletions packages/playwright-core/src/common/timeoutSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions tests/library/inspector/pause.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 4f8680f

Please sign in to comment.