webdriverio 9.5.6 → 9.5.7

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/build/index.js CHANGED
@@ -3226,6 +3226,7 @@ var NAME_POLYFILL = "var __defProp = Object.defineProperty;var __name = function
3226
3226
  var PolyfillManager = class _PolyfillManager extends SessionManager {
3227
3227
  #initialize;
3228
3228
  #browser;
3229
+ #scriptsRegisteredInContexts = /* @__PURE__ */ new Set();
3229
3230
  constructor(browser) {
3230
3231
  super(browser, _PolyfillManager.name);
3231
3232
  this.#browser = browser;
@@ -3234,28 +3235,37 @@ var PolyfillManager = class _PolyfillManager extends SessionManager {
3234
3235
  return;
3235
3236
  }
3236
3237
  this.#initialize = Promise.all([
3237
- this.#registerScripts(),
3238
+ this.#browser.browsingContextGetTree({}).then(({ contexts }) => {
3239
+ return Promise.all(contexts.map((context) => this.#registerScripts(context)));
3240
+ }),
3238
3241
  this.#browser.sessionSubscribe({
3239
3242
  events: ["browsingContext.contextCreated"]
3240
3243
  })
3241
- ]).then(() => {
3242
- log5.info("polyfill script added");
3243
- return true;
3244
- }, () => false);
3244
+ ]).then(() => true, () => false);
3245
3245
  this.#browser.on("browsingContext.contextCreated", this.#registerScripts.bind(this));
3246
3246
  }
3247
3247
  removeListeners() {
3248
3248
  super.removeListeners();
3249
3249
  this.#browser.off("browsingContext.contextCreated", this.#registerScripts.bind(this));
3250
3250
  }
3251
- #registerScripts() {
3252
- const polyfill = (polyfill2) => {
3253
- const closure = new Function(polyfill2);
3254
- return closure();
3255
- };
3251
+ #registerScripts(context) {
3252
+ if (this.#scriptsRegisteredInContexts.has(context.context)) {
3253
+ return;
3254
+ }
3255
+ const functionDeclaration = `(() => {${NAME_POLYFILL}})()`;
3256
+ log5.info(`Adding polyfill script to context with id ${context.context}`);
3257
+ this.#scriptsRegisteredInContexts.add(context.context);
3256
3258
  return Promise.all([
3257
- this.#browser.addInitScript(polyfill, NAME_POLYFILL),
3258
- this.#browser.execute(polyfill, NAME_POLYFILL)
3259
+ !context.parent ? this.#browser.scriptAddPreloadScript({
3260
+ functionDeclaration,
3261
+ contexts: [context.context]
3262
+ }) : Promise.resolve(),
3263
+ this.#browser.scriptCallFunction({
3264
+ functionDeclaration,
3265
+ target: context,
3266
+ awaitPromise: false
3267
+ }).catch(() => {
3268
+ })
3259
3269
  ]);
3260
3270
  }
3261
3271
  async initialize() {
@@ -1,5 +1,13 @@
1
1
  import { SessionManager } from './session.js';
2
2
  export declare function getPolyfillManager(browser: WebdriverIO.Browser): PolyfillManager;
3
+ /**
4
+ * A polyfill to set `__name` to the global scope which is needed for WebdriverIO to properly
5
+ * execute custom (preload) scripts. When using `tsx` Esbuild runs some optimizations which
6
+ * assume that the file contains these global variables. This is a workaround until this issue
7
+ * is fixed.
8
+ *
9
+ * @see https://github.com/evanw/esbuild/issues/2605
10
+ */
3
11
  export declare const NAME_POLYFILL: string;
4
12
  /**
5
13
  * This class is responsible for setting polyfill scripts in the browser.
@@ -1 +1 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../src/session/polyfill.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,mBAE9D;AAID,eAAO,MAAM,aAAa,QAKzB,CAAA;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,cAAc;;gBAInC,OAAO,EAAE,WAAW,CAAC,OAAO;IA4BxC,eAAe;IAyBT,UAAU;CAGnB"}
1
+ {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../src/session/polyfill.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,mBAE9D;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,QAKzB,CAAA;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,cAAc;;gBAKnC,OAAO,EAAE,WAAW,CAAC,OAAO;IA2BxC,eAAe;IAgCT,UAAU;CAGnB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "webdriverio",
3
3
  "description": "Next-gen browser and mobile automation test framework for Node.js",
4
- "version": "9.5.6",
4
+ "version": "9.5.7",
5
5
  "homepage": "https://webdriver.io",
6
6
  "author": "Christian Bromann <mail@bromann.dev>",
7
7
  "license": "MIT",
@@ -110,5 +110,5 @@
110
110
  "optional": true
111
111
  }
112
112
  },
113
- "gitHead": "7b29d6eb39620bd1469ba1a3ac37407c7958e56a"
113
+ "gitHead": "a273d38d5724c27656fa6e8d7b8b79a716a9f00a"
114
114
  }