playwright 1.56.0-alpha-1757090131000 → 1.56.0-alpha-2025-09-07

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,8 +98,11 @@ class IsolatedContextFactory extends BaseContextFactory {
98
98
  async _doObtainBrowser(clientInfo) {
99
99
  await injectCdpPort(this.config.browser);
100
100
  const browserType = playwright[this.config.browser.browserName];
101
+ const tracesDir = await (0, import_config.outputFile)(this.config, clientInfo.rootPath, `traces`);
102
+ if (this.config.saveTrace)
103
+ await startTraceServer(this.config, tracesDir);
101
104
  return browserType.launch({
102
- tracesDir: await startTraceServer(this.config, clientInfo.rootPath),
105
+ tracesDir,
103
106
  ...this.config.browser.launchOptions,
104
107
  handleSIGINT: false,
105
108
  handleSIGTERM: false
@@ -150,19 +153,26 @@ class PersistentContextFactory {
150
153
  await injectCdpPort(this.config.browser);
151
154
  (0, import_log.testDebug)("create browser context (persistent)");
152
155
  const userDataDir = this.config.browser.userDataDir ?? await this._createUserDataDir(clientInfo.rootPath);
153
- const tracesDir = await startTraceServer(this.config, clientInfo.rootPath);
156
+ const tracesDir = await (0, import_config.outputFile)(this.config, clientInfo.rootPath, `traces`);
157
+ if (this.config.saveTrace)
158
+ await startTraceServer(this.config, tracesDir);
154
159
  this._userDataDirs.add(userDataDir);
155
160
  (0, import_log.testDebug)("lock user data dir", userDataDir);
156
161
  const browserType = playwright[this.config.browser.browserName];
157
162
  for (let i = 0; i < 5; i++) {
163
+ const launchOptions = {
164
+ tracesDir,
165
+ ...this.config.browser.launchOptions,
166
+ ...this.config.browser.contextOptions,
167
+ handleSIGINT: false,
168
+ handleSIGTERM: false,
169
+ ignoreDefaultArgs: [
170
+ "--disable-extensions"
171
+ ],
172
+ assistantMode: true
173
+ };
158
174
  try {
159
- const browserContext = await browserType.launchPersistentContext(userDataDir, {
160
- tracesDir,
161
- ...this.config.browser.launchOptions,
162
- ...this.config.browser.contextOptions,
163
- handleSIGINT: false,
164
- handleSIGTERM: false
165
- });
175
+ const browserContext = await browserType.launchPersistentContext(userDataDir, launchOptions);
166
176
  const close = () => this._closeBrowserContext(browserContext, userDataDir);
167
177
  return { browserContext, close };
168
178
  } catch (error) {
@@ -208,15 +218,13 @@ async function findFreePort() {
208
218
  server.on("error", reject);
209
219
  });
210
220
  }
211
- async function startTraceServer(config, rootPath) {
221
+ async function startTraceServer(config, tracesDir) {
212
222
  if (!config.saveTrace)
213
- return void 0;
214
- const tracesDir = await (0, import_config.outputFile)(config, rootPath, `traces-${Date.now()}`);
223
+ return;
215
224
  const server = await (0, import_server.startTraceViewerServer)();
216
225
  const urlPrefix = server.urlPrefix("human-readable");
217
226
  const url = urlPrefix + "/trace/index.html?trace=" + tracesDir + "/trace.json";
218
227
  console.error("\nTrace viewer listening on " + url);
219
- return tracesDir;
220
228
  }
221
229
  function createHash(data) {
222
230
  return import_crypto.default.createHash("sha256").update(data).digest("hex").slice(0, 7);
@@ -155,6 +155,10 @@ class Context {
155
155
  await context.route(`*://${origin}/**`, (route) => route.abort("blockedbyclient"));
156
156
  }
157
157
  }
158
+ async ensureBrowserContext() {
159
+ const { browserContext } = await this._ensureBrowserContext();
160
+ return browserContext;
161
+ }
158
162
  _ensureBrowserContext() {
159
163
  if (!this._browserContextPromise) {
160
164
  this._browserContextPromise = this._setupBrowserContext();
@@ -177,10 +181,10 @@ class Context {
177
181
  browserContext.on("page", (page) => this._onPageCreated(page));
178
182
  if (this.config.saveTrace) {
179
183
  await browserContext.tracing.start({
180
- name: "trace",
181
- screenshots: false,
184
+ name: "trace-" + Date.now(),
185
+ screenshots: true,
182
186
  snapshots: true,
183
- sources: false
187
+ _live: true
184
188
  });
185
189
  }
186
190
  return result;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var tracing_exports = {};
20
+ __export(tracing_exports, {
21
+ default: () => tracing_default
22
+ });
23
+ module.exports = __toCommonJS(tracing_exports);
24
+ var import_bundle = require("../../sdk/bundle");
25
+ var import_tool = require("./tool");
26
+ const tracingStart = (0, import_tool.defineTool)({
27
+ capability: "tracing",
28
+ schema: {
29
+ name: "browser_start_tracing",
30
+ title: "Start tracing",
31
+ description: "Start trace recording",
32
+ inputSchema: import_bundle.z.object({}),
33
+ type: "readOnly"
34
+ },
35
+ handle: async (context, params, response) => {
36
+ const browserContext = await context.ensureBrowserContext();
37
+ const tracesDir = await context.outputFile(`traces`);
38
+ const name = "trace-" + Date.now();
39
+ await browserContext.tracing.start({
40
+ name,
41
+ screenshots: true,
42
+ snapshots: true,
43
+ _live: true
44
+ });
45
+ const traceLegend = `- Action log: ${tracesDir}/${name}.trace
46
+ - Network log: ${tracesDir}/${name}.network
47
+ - Resources with content by sha1: ${tracesDir}/resources`;
48
+ response.addResult(`Tracing started, saving to ${tracesDir}.
49
+ ${traceLegend}`);
50
+ browserContext.tracing[traceLegendSymbol] = traceLegend;
51
+ }
52
+ });
53
+ const tracingStop = (0, import_tool.defineTool)({
54
+ capability: "tracing",
55
+ schema: {
56
+ name: "browser_stop_tracing",
57
+ title: "Stop tracing",
58
+ description: "Stop trace recording",
59
+ inputSchema: import_bundle.z.object({}),
60
+ type: "readOnly"
61
+ },
62
+ handle: async (context, params, response) => {
63
+ const browserContext = await context.ensureBrowserContext();
64
+ await browserContext.tracing.stop();
65
+ const traceLegend = browserContext.tracing[traceLegendSymbol];
66
+ response.addResult(`Tracing stopped.
67
+ ${traceLegend}`);
68
+ }
69
+ });
70
+ var tracing_default = [
71
+ tracingStart,
72
+ tracingStop
73
+ ];
74
+ const traceLegendSymbol = Symbol("tracesDir");
@@ -45,8 +45,9 @@ var import_navigate = __toESM(require("./tools/navigate"));
45
45
  var import_network = __toESM(require("./tools/network"));
46
46
  var import_pdf = __toESM(require("./tools/pdf"));
47
47
  var import_snapshot = __toESM(require("./tools/snapshot"));
48
- var import_tabs = __toESM(require("./tools/tabs"));
49
48
  var import_screenshot = __toESM(require("./tools/screenshot"));
49
+ var import_tabs = __toESM(require("./tools/tabs"));
50
+ var import_tracing = __toESM(require("./tools/tracing"));
50
51
  var import_wait = __toESM(require("./tools/wait"));
51
52
  var import_verify = __toESM(require("./tools/verify"));
52
53
  const allTools = [
@@ -65,6 +66,7 @@ const allTools = [
65
66
  ...import_screenshot.default,
66
67
  ...import_snapshot.default,
67
68
  ...import_tabs.default,
69
+ ...import_tracing.default,
68
70
  ...import_wait.default,
69
71
  ...import_verify.default
70
72
  ];
@@ -85,8 +85,14 @@ function createServer(name, version, backend, runHeartbeat) {
85
85
  const capabilities = server.getClientCapabilities();
86
86
  let clientRoots = [];
87
87
  if (capabilities?.roots) {
88
- const { roots } = await server.listRoots(void 0, { timeout: 2e3 }).catch(() => ({ roots: [] }));
89
- clientRoots = roots;
88
+ for (let i = 0; i < 2; i++) {
89
+ try {
90
+ const { roots } = await server.listRoots(void 0, { timeout: 2e3 });
91
+ clientRoots = roots;
92
+ } catch (e) {
93
+ continue;
94
+ }
95
+ }
90
96
  }
91
97
  const clientVersion = server.getClientVersion() ?? { name: "unknown", version: "unknown" };
92
98
  await backend.initialize?.(server, clientVersion, clientRoots);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright",
3
- "version": "1.56.0-alpha-1757090131000",
3
+ "version": "1.56.0-alpha-2025-09-07",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "license": "Apache-2.0",
66
66
  "dependencies": {
67
- "playwright-core": "1.56.0-alpha-1757090131000"
67
+ "playwright-core": "1.56.0-alpha-2025-09-07"
68
68
  },
69
69
  "optionalDependencies": {
70
70
  "fsevents": "2.3.2"