Skip to content

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

chore: remove graceful browser.close cleanup (#27916)

Pavel Feldman0f2de59b7ca6
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts
index 3b7b41497b..0bc14f45e1 100644
--- a/packages/playwright-core/src/server/browserContext.ts
+++ b/packages/playwright-core/src/server/browserContext.ts
@@ -240,13 +240,7 @@ export abstract class BrowserContext extends SdkObject {
// at the same time.
return;
}
- const gotClosedGracefully = this._closedStatus === 'closing';
- this._closedStatus = 'closed';
- if (!gotClosedGracefully) {
- this._deleteAllDownloads();
- this._downloads.clear();
- }
- this.tracing.dispose().catch(() => {});
+ this.tracing.abort();
if (this._isPersistentContext)
this.onClosePersistent();
this._closePromiseFulfill!(new Error('Context closed'));
@@ -422,7 +416,7 @@ export abstract class BrowserContext extends SdkObject {
for (const harRecorder of this._harRecorders.values())
await harRecorder.flush();
- await this.tracing.dispose();
+ await this.tracing.flush();
// Cleanup.
const promises: Promise<void>[] = [];
diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.ts
index b7af65fe51..425d514650 100644
--- a/packages/playwright-core/src/server/fetch.ts
+++ b/packages/playwright-core/src/server/fetch.ts
@@ -551,7 +551,7 @@ export class GlobalAPIRequestContext extends APIRequestContext {
}
override async dispose() {
- await this._tracing.dispose();
+ await this._tracing.flush();
await this._tracing.deleteTmpTracesDir();
this._disposeImpl();
}
diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.ts
index 64ba58811c..f5e84f442f 100644
--- a/packages/playwright-core/src/server/trace/recorder/tracing.ts
+++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts
@@ -249,9 +249,13 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
return this._tracesTmpDir;
}
- async dispose() {
+ abort() {
this._snapshotter?.dispose();
this._harTracer.stop();
+ }
+
+ async flush() {
+ this.abort();
await this._fs.syncAndGetError();
}