playwright-core 1.56.0-alpha-2025-09-12 → 1.56.0-alpha-2025-09-14

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.
package/browsers.json CHANGED
@@ -39,7 +39,7 @@
39
39
  },
40
40
  {
41
41
  "name": "webkit",
42
- "revision": "2209",
42
+ "revision": "2210",
43
43
  "installByDefault": true,
44
44
  "revisionOverrides": {
45
45
  "debian11-x64": "2105",
@@ -33,6 +33,9 @@ class BidiConnection {
33
33
  this._lastId = 0;
34
34
  this._closed = false;
35
35
  this._browsingContextToSession = /* @__PURE__ */ new Map();
36
+ this._realmToBrowsingContext = /* @__PURE__ */ new Map();
37
+ // TODO: shared/service workers might have multiple owner realms.
38
+ this._realmToOwnerRealm = /* @__PURE__ */ new Map();
36
39
  this._transport = transport;
37
40
  this._onDisconnect = onDisconnect;
38
41
  this._protocolLogger = protocolLogger;
@@ -54,11 +57,30 @@ class BidiConnection {
54
57
  this._protocolLogger("receive", message);
55
58
  const object = message;
56
59
  if (object.type === "event") {
60
+ if (object.method === "script.realmCreated") {
61
+ if ("context" in object.params)
62
+ this._realmToBrowsingContext.set(object.params.realm, object.params.context);
63
+ if (object.params.type === "dedicated-worker")
64
+ this._realmToOwnerRealm.set(object.params.realm, object.params.owners[0]);
65
+ } else if (object.method === "script.realmDestroyed") {
66
+ this._realmToBrowsingContext.delete(object.params.realm);
67
+ this._realmToOwnerRealm.delete(object.params.realm);
68
+ }
57
69
  let context;
58
- if ("context" in object.params)
70
+ let realm;
71
+ if ("context" in object.params) {
59
72
  context = object.params.context;
60
- else if (object.method === "log.entryAdded" || object.method === "script.message")
73
+ } else if (object.method === "log.entryAdded" || object.method === "script.message") {
61
74
  context = object.params.source?.context;
75
+ realm = object.params.source?.realm;
76
+ } else if (object.method === "script.realmCreated" && object.params.type === "dedicated-worker") {
77
+ realm = object.params.owners[0];
78
+ }
79
+ if (!context && realm) {
80
+ while (this._realmToOwnerRealm.get(realm))
81
+ realm = this._realmToOwnerRealm.get(realm);
82
+ context = this._realmToBrowsingContext.get(realm);
83
+ }
62
84
  if (context) {
63
85
  const session = this._browsingContextToSession.get(context);
64
86
  if (session) {
@@ -35,8 +35,8 @@ module.exports = __toCommonJS(bidiPage_exports);
35
35
  var import_eventsHelper = require("../utils/eventsHelper");
36
36
  var dialog = __toESM(require("../dialog"));
37
37
  var dom = __toESM(require("../dom"));
38
- var import_page = require("../page");
39
38
  var import_bidiBrowser = require("./bidiBrowser");
39
+ var import_page = require("../page");
40
40
  var import_bidiExecutionContext = require("./bidiExecutionContext");
41
41
  var import_bidiInput = require("./bidiInput");
42
42
  var import_bidiNetworkManager = require("./bidiNetworkManager");
@@ -46,6 +46,7 @@ const UTILITY_WORLD_NAME = "__playwright_utility_world__";
46
46
  const kPlaywrightBindingChannel = "playwrightChannel";
47
47
  class BidiPage {
48
48
  constructor(browserContext, bidiSession, opener) {
49
+ this._realmToWorkerContext = /* @__PURE__ */ new Map();
49
50
  this._sessionListeners = [];
50
51
  this._initScriptIds = /* @__PURE__ */ new Map();
51
52
  this._session = bidiSession;
@@ -108,6 +109,13 @@ class BidiPage {
108
109
  }
109
110
  }
110
111
  _onRealmCreated(realmInfo) {
112
+ if (realmInfo.type === "dedicated-worker") {
113
+ const delegate2 = new import_bidiExecutionContext.BidiExecutionContext(this._session, realmInfo);
114
+ const worker = new import_page.Worker(this._page, realmInfo.origin);
115
+ this._realmToWorkerContext.set(realmInfo.realm, worker.createExecutionContext(delegate2));
116
+ this._page.addWorker(realmInfo.realm, worker);
117
+ return;
118
+ }
111
119
  if (this._realmToContext.has(realmInfo.realm))
112
120
  return;
113
121
  if (realmInfo.type !== "window")
@@ -146,11 +154,17 @@ class BidiPage {
146
154
  }
147
155
  _onRealmDestroyed(params) {
148
156
  const context = this._realmToContext.get(params.realm);
149
- if (!context)
150
- return false;
151
- this._realmToContext.delete(params.realm);
152
- context.frame._contextDestroyed(context);
153
- return true;
157
+ if (context) {
158
+ this._realmToContext.delete(params.realm);
159
+ context.frame._contextDestroyed(context);
160
+ return true;
161
+ }
162
+ const existed = this._realmToWorkerContext.delete(params.realm);
163
+ if (existed) {
164
+ this._page.removeWorker(params.realm);
165
+ return true;
166
+ }
167
+ return false;
154
168
  }
155
169
  // TODO: route the message directly to the browser
156
170
  _onBrowsingContextDestroyed(params) {
@@ -240,7 +254,7 @@ ${params.stackTrace?.callFrames.map((f) => {
240
254
  if (params.type !== "console")
241
255
  return;
242
256
  const entry = params;
243
- const context = this._realmToContext.get(params.source.realm);
257
+ const context = this._realmToContext.get(params.source.realm) ?? this._realmToWorkerContext.get(params.source.realm);
244
258
  if (!context)
245
259
  return;
246
260
  const callFrame = params.stackTrace?.callFrames[0];
@@ -394,6 +394,7 @@ class FrameSession {
394
394
  if (!this._isMainFrame())
395
395
  this._addRendererListeners();
396
396
  this._addBrowserListeners();
397
+ this._bufferedAttachedToTargetEvents = [];
397
398
  const promises = [
398
399
  this._client.send("Page.enable"),
399
400
  this._client.send("Page.getFrameTree").then(({ frameTree }) => {
@@ -401,6 +402,10 @@ class FrameSession {
401
402
  this._handleFrameTree(frameTree);
402
403
  this._addRendererListeners();
403
404
  }
405
+ const attachedToTargetEvents = this._bufferedAttachedToTargetEvents || [];
406
+ this._bufferedAttachedToTargetEvents = void 0;
407
+ for (const event of attachedToTargetEvents)
408
+ this._onAttachedToTarget(event);
404
409
  const localFrames = this._isMainFrame() ? this._page.frames() : [this._page.frameManager.frame(this._targetId)];
405
410
  for (const frame of localFrames) {
406
411
  this._client._sendMayFail("Page.createIsolatedWorld", {
@@ -593,6 +598,10 @@ class FrameSession {
593
598
  this._onExecutionContextDestroyed(contextId);
594
599
  }
595
600
  _onAttachedToTarget(event) {
601
+ if (this._bufferedAttachedToTargetEvents) {
602
+ this._bufferedAttachedToTargetEvents.push(event);
603
+ return;
604
+ }
596
605
  const session = this._client.createChildSession(event.sessionId);
597
606
  if (event.targetInfo.type === "iframe") {
598
607
  const targetId = event.targetInfo.targetId;