Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: pass "live" flag explicitly instead of through env var (#38217)
Dmitry Gozman2db5effacd2e
diff --git a/packages/playwright-core/src/client/tracing.ts b/packages/playwright-core/src/client/tracing.tsindex 536d1673b8..a3c7bd53a3 100644--- a/packages/playwright-core/src/client/tracing.ts+++ b/packages/playwright-core/src/client/tracing.ts@@ -22,6 +22,7 @@ import type * as channels from '@protocol/channels';export class Tracing extends ChannelOwner<channels.TracingChannel> implements api.Tracing {private _includeSources = false;+ private _isLive = false;_tracesDir: string | undefined;private _stacksId: string | undefined;private _isTracing = false;@@ -37,6 +38,7 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements apasync start(options: { name?: string, title?: string, snapshots?: boolean, screenshots?: boolean, sources?: boolean, _live?: boolean } = {}) {await this._wrapApiCall(async () => {this._includeSources = !!options.sources;+ this._isLive = !!options._live;await this._channel.tracingStart({name: options.name,snapshots: options.snapshots,@@ -44,14 +46,14 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements aplive: options._live,});const { traceName } = await this._channel.tracingStartChunk({ name: options.name, title: options.title });- await this._startCollectingStacks(traceName);+ await this._startCollectingStacks(traceName, this._isLive);});}async startChunk(options: { name?: string, title?: string } = {}) {await this._wrapApiCall(async () => {const { traceName } = await this._channel.tracingStartChunk(options);- await this._startCollectingStacks(traceName);+ await this._startCollectingStacks(traceName, this._isLive);});}@@ -63,12 +65,12 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements apawait this._channel.tracingGroupEnd();}- private async _startCollectingStacks(traceName: string) {+ private async _startCollectingStacks(traceName: string, live: boolean) {if (!this._isTracing) {this._isTracing = true;this._connection.setIsTracing(true);}- const result = await this._connection.localUtils()?.tracingStarted({ tracesDir: this._tracesDir, traceName });+ const result = await this._connection.localUtils()?.tracingStarted({ tracesDir: this._tracesDir, traceName, live });this._stacksId = result?.stacksId;}diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.tsindex 81bb78cdb7..c2f8605829 100644--- a/packages/playwright-core/src/protocol/validator.ts+++ b/packages/playwright-core/src/protocol/validator.ts@@ -317,6 +317,7 @@ scheme.LocalUtilsConnectResult = tObject({scheme.LocalUtilsTracingStartedParams = tObject({tracesDir: tOptional(tString),traceName: tString,+ live: tOptional(tBoolean),});scheme.LocalUtilsTracingStartedResult = tObject({stacksId: tString,diff --git a/packages/playwright-core/src/server/localUtils.ts b/packages/playwright-core/src/server/localUtils.tsindex b58f2aa855..685a0f64f0 100644--- a/packages/playwright-core/src/server/localUtils.ts+++ b/packages/playwright-core/src/server/localUtils.ts@@ -38,6 +38,7 @@ export type StackSession = {writer: Promise<void>;tmpDir: string | undefined;callStacks: channels.ClientSideCallMetadata[];+ live?: boolean;};export async function zip(progress: Progress, stackSessions: Map<string, StackSession>, params: channels.LocalUtilsZipParams): Promise<void> {@@ -194,7 +195,7 @@ export async function tracingStarted(progress: Progress, stackSessions: Map<striif (!params.tracesDir)tmpDir = await progress.race(fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-tracing-')));const traceStacksFile = path.join(params.tracesDir || tmpDir!, params.traceName + '.stacks');- stackSessions.set(traceStacksFile, { callStacks: [], file: traceStacksFile, writer: Promise.resolve(), tmpDir });+ stackSessions.set(traceStacksFile, { callStacks: [], file: traceStacksFile, writer: Promise.resolve(), tmpDir, live: params.live });return { stacksId: traceStacksFile };}@@ -205,7 +206,7 @@ export async function traceDiscarded(progress: Progress, stackSessions: Map<striexport function addStackToTracingNoReply(stackSessions: Map<string, StackSession>, params: channels.LocalUtilsAddStackToTracingNoReplyParams) {for (const session of stackSessions.values()) {session.callStacks.push(params.callData);- if (process.env.PW_LIVE_TRACE_STACKS) {+ if (session.live) {session.writer = session.writer.then(() => {const buffer = Buffer.from(JSON.stringify(serializeClientSideCallMetadata(session.callStacks)));return fs.promises.writeFile(session.file, buffer);diff --git a/packages/playwright/src/runner/testRunner.ts b/packages/playwright/src/runner/testRunner.tsindex 426c90d19c..596ac10a50 100644--- a/packages/playwright/src/runner/testRunner.ts+++ b/packages/playwright/src/runner/testRunner.ts@@ -324,10 +324,6 @@ export class TestRunner extends EventEmitter<TestRunnerEventMap> {...(params.updateSourceMethod ? { updateSourceMethod: params.updateSourceMethod } : {}),...(params.workers ? { workers: params.workers } : {}),};- if (params.trace === 'on')- process.env.PW_LIVE_TRACE_STACKS = '1';- else- process.env.PW_LIVE_TRACE_STACKS = undefined;const config = await this._loadConfigOrReportError(new InternalReporter([userReporter]), overrides);if (!config)diff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.tsindex ce94be4aaf..d001a36af4 100644--- a/packages/protocol/src/channels.d.ts+++ b/packages/protocol/src/channels.d.ts@@ -533,9 +533,11 @@ export type LocalUtilsConnectResult = {export type LocalUtilsTracingStartedParams = {tracesDir?: string,traceName: string,+ live?: boolean,};export type LocalUtilsTracingStartedOptions = {tracesDir?: string,+ live?: boolean,};export type LocalUtilsTracingStartedResult = {stacksId: string,diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.ymlindex dab1ea1cd1..1629cf5fed 100644--- a/packages/protocol/src/protocol.yml+++ b/packages/protocol/src/protocol.yml@@ -709,6 +709,7 @@ LocalUtils:parameters:tracesDir: string?traceName: string+ live: boolean?returns:stacksId: stringdiff --git a/tests/mcp/tracing.spec.ts b/tests/mcp/tracing.spec.tsindex c790aa926c..420534c92f 100644--- a/tests/mcp/tracing.spec.ts+++ b/tests/mcp/tracing.spec.ts@@ -64,6 +64,7 @@ test('check that trace is saved with browser_start_tracing', async ({ startClienexpect(files).toEqual(['resources',expect.stringMatching(/trace-\d+\.network/),+ expect.stringMatching(/trace-\d+\.stacks/),expect.stringMatching(/trace-\d+\.trace/),]);});@@ -102,6 +103,7 @@ test('check that trace is saved with browser_start_tracing (no output dir)', asyexpect(files).toEqual(['resources',expect.stringMatching(/trace-\d+\.network/),+ expect.stringMatching(/trace-\d+\.stacks/),expect.stringMatching(/trace-\d+\.trace/),]);});