Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Dmitry Gozman4f8680f7a393
diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts
index 7fbb62ddd8..1284ff6625 100644
--- a/packages/playwright-core/src/client/browserContext.ts
+++ b/packages/playwright-core/src/client/browserContext.ts
@@ -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(() => {});
diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts
index 20cb43cf42..f6bfa41d05 100644
--- a/packages/playwright-core/src/client/page.ts
+++ b/packages/playwright-core/src/client/page.ts
@@ -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> {
diff --git a/packages/playwright-core/src/common/timeoutSettings.ts b/packages/playwright-core/src/common/timeoutSettings.ts
index 7b923136de..65c8be1ecf 100644
--- a/packages/playwright-core/src/common/timeoutSettings.ts
+++ b/packages/playwright-core/src/common/timeoutSettings.ts
@@ -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;
diff --git a/tests/library/inspector/pause.spec.ts b/tests/library/inspector/pause.spec.ts
index d6c2f2d258..1c387892a7 100644
--- a/tests/library/inspector/pause.spec.ts
+++ b/tests/library/inspector/pause.spec.ts
@@ -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');