webdriverio 9.0.5 → 9.0.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
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/index.ts
8
- import logger18 from "@wdio/logger";
8
+ import logger19 from "@wdio/logger";
9
9
  import WebDriver, { DEFAULTS } from "webdriver";
10
10
  import { validateConfig } from "@wdio/config";
11
11
  import { enableFileLogging, wrapCommand as wrapCommand3 } from "@wdio/utils";
@@ -17,7 +17,7 @@ import { webdriverMonad as webdriverMonad2, wrapCommand as wrapCommand2 } from "
17
17
 
18
18
  // src/middlewares.ts
19
19
  import { ELEMENT_KEY as ELEMENT_KEY18 } from "webdriver";
20
- import { getBrowserObject as getBrowserObject27 } from "@wdio/utils";
20
+ import { getBrowserObject as getBrowserObject32 } from "@wdio/utils";
21
21
 
22
22
  // src/utils/implicitWait.ts
23
23
  import logger from "@wdio/logger";
@@ -78,10 +78,10 @@ import { URL as URL2 } from "node:url";
78
78
  import cssValue from "css-value";
79
79
  import rgb2hex from "rgb2hex";
80
80
  import GraphemeSplitter from "grapheme-splitter";
81
- import logger17 from "@wdio/logger";
81
+ import logger18 from "@wdio/logger";
82
82
  import isPlainObject from "is-plain-obj";
83
83
  import { ELEMENT_KEY as ELEMENT_KEY17 } from "webdriver";
84
- import { UNICODE_CHARACTERS as UNICODE_CHARACTERS2, asyncIterators, getBrowserObject as getBrowserObject26 } from "@wdio/utils";
84
+ import { UNICODE_CHARACTERS as UNICODE_CHARACTERS2, asyncIterators, getBrowserObject as getBrowserObject31 } from "@wdio/utils";
85
85
 
86
86
  // src/commands/browser.ts
87
87
  var browser_exports = {};
@@ -2535,6 +2535,9 @@ async function emulate(scope, options) {
2535
2535
  throw new Error(`Invalid scope "${scope}", expected one of "geolocation", "userAgent", "colorScheme", "onLine", "device" or "clock"`);
2536
2536
  }
2537
2537
 
2538
+ // src/commands/browser/execute.ts
2539
+ import { getBrowserObject as getBrowserObject2 } from "@wdio/utils";
2540
+
2538
2541
  // src/utils/bidi/value.ts
2539
2542
  import { ELEMENT_KEY as ELEMENT_KEY7 } from "webdriver";
2540
2543
  var TYPE_CONSTANT = "type";
@@ -2792,14 +2795,72 @@ var ReferenceValue = class {
2792
2795
  }
2793
2796
  };
2794
2797
 
2798
+ // src/context.ts
2799
+ import logger4 from "@wdio/logger";
2800
+ var contextManager = /* @__PURE__ */ new Map();
2801
+ var log4 = logger4("webdriverio:ContextManager");
2802
+ function getContextManager(browser) {
2803
+ const existingContextManager = contextManager.get(browser);
2804
+ if (existingContextManager) {
2805
+ return existingContextManager;
2806
+ }
2807
+ const newContext = new ContextManager(browser);
2808
+ contextManager.set(browser, newContext);
2809
+ return newContext;
2810
+ }
2811
+ var ContextManager = class {
2812
+ #browser;
2813
+ #initialize;
2814
+ #currentContext;
2815
+ constructor(browser) {
2816
+ this.#browser = browser;
2817
+ if (!browser.isBidi || process.env.VITEST_WORKER_ID || browser.options?.automationProtocol !== "webdriver") {
2818
+ this.#initialize = Promise.resolve(true);
2819
+ return;
2820
+ }
2821
+ this.#initialize = this.#browser.sessionSubscribe({
2822
+ events: ["browsingContext.navigationStarted"]
2823
+ }).then(() => true, () => false);
2824
+ this.#browser.on("browsingContext.navigationStarted", this.#handleNavigationStarted.bind(this));
2825
+ }
2826
+ async initialize() {
2827
+ return this.#initialize;
2828
+ }
2829
+ /**
2830
+ * We use this handler to observe the current context which is used to navigate to a certain url.
2831
+ * This is most likely the context that the user is using. However if a frame was loaded on the page
2832
+ * then this handler is triggered with the context of the frame. To find out which context we are in
2833
+ * we use the `getWindowHandle` method to validate our assumption before setting the `#currentContext`
2834
+ * value.
2835
+ *
2836
+ * @param {local.BrowsingContextNavigationInfo} context browsing context used to navigate
2837
+ */
2838
+ #handleNavigationStarted(context) {
2839
+ this.#browser.getWindowHandle().then((windowHandle) => {
2840
+ if (context.context === windowHandle) {
2841
+ log4.info(`Update current context: ${context.context}`);
2842
+ this.#currentContext = context.context;
2843
+ }
2844
+ });
2845
+ }
2846
+ async getCurrentContext() {
2847
+ if (!this.#currentContext) {
2848
+ this.#currentContext = await this.#browser.getWindowHandle();
2849
+ }
2850
+ return this.#currentContext;
2851
+ }
2852
+ };
2853
+
2795
2854
  // src/commands/browser/execute.ts
2796
2855
  async function execute(script, ...args) {
2797
2856
  if (typeof script !== "string" && typeof script !== "function") {
2798
2857
  throw new Error("number or type of arguments don't agree with execute protocol command");
2799
2858
  }
2800
- if (this.isBidi) {
2801
- const context = await this.getWindowHandle();
2802
- const result = await this.scriptCallFunction({
2859
+ if (this.isBidi && !this.isMultiremote) {
2860
+ const browser = getBrowserObject2(this);
2861
+ const contextManager2 = getContextManager(browser);
2862
+ const context = await contextManager2.getCurrentContext();
2863
+ const result = await browser.scriptCallFunction({
2803
2864
  functionDeclaration: script.toString(),
2804
2865
  awaitPromise: false,
2805
2866
  arguments: args.map((arg) => LocalValue.getArgument(arg)),
@@ -2816,12 +2877,15 @@ async function execute(script, ...args) {
2816
2877
  }
2817
2878
 
2818
2879
  // src/commands/browser/executeAsync.ts
2880
+ import { getBrowserObject as getBrowserObject3 } from "@wdio/utils";
2819
2881
  async function executeAsync(script, ...args) {
2820
2882
  if (typeof script !== "string" && typeof script !== "function") {
2821
2883
  throw new Error("number or type of arguments don't agree with execute protocol command");
2822
2884
  }
2823
- if (this.isBidi) {
2824
- const context = await this.getWindowHandle();
2885
+ if (this.isBidi && !this.isMultiremote) {
2886
+ const browser = getBrowserObject3(this);
2887
+ const contextManager2 = getContextManager(browser);
2888
+ const context = await contextManager2.getCurrentContext();
2825
2889
  const functionDeclaration = `function (...args) {
2826
2890
  return new Promise(async (resolve, reject) => {
2827
2891
  try {
@@ -2831,7 +2895,7 @@ async function executeAsync(script, ...args) {
2831
2895
  }
2832
2896
  })
2833
2897
  }`;
2834
- const result = await this.scriptCallFunction({
2898
+ const result = await browser.scriptCallFunction({
2835
2899
  functionDeclaration,
2836
2900
  awaitPromise: true,
2837
2901
  arguments: args.map((arg) => LocalValue.getArgument(arg)),
@@ -2861,9 +2925,9 @@ async function getCookies(names) {
2861
2925
  }
2862
2926
 
2863
2927
  // src/commands/browser/getPuppeteer.ts
2864
- import logger4 from "@wdio/logger";
2928
+ import logger5 from "@wdio/logger";
2865
2929
  import { userImport } from "@wdio/utils";
2866
- var log4 = logger4("webdriverio");
2930
+ var log5 = logger5("webdriverio");
2867
2931
  async function getPuppeteer() {
2868
2932
  const puppeteer = await userImport("puppeteer-core");
2869
2933
  if (!puppeteer) {
@@ -2872,7 +2936,7 @@ async function getPuppeteer() {
2872
2936
  );
2873
2937
  }
2874
2938
  if (this.puppeteer?.connected) {
2875
- log4.debug("Reusing existing puppeteer session");
2939
+ log5.debug("Reusing existing puppeteer session");
2876
2940
  return this.puppeteer;
2877
2941
  }
2878
2942
  const { headers } = this.options;
@@ -2940,9 +3004,9 @@ async function getPuppeteer() {
2940
3004
  }
2941
3005
 
2942
3006
  // src/commands/browser/getWindowSize.ts
2943
- import { getBrowserObject as getBrowserObject2 } from "@wdio/utils";
3007
+ import { getBrowserObject as getBrowserObject4 } from "@wdio/utils";
2944
3008
  async function getWindowSize() {
2945
- const browser = getBrowserObject2(this);
3009
+ const browser = getBrowserObject4(this);
2946
3010
  const { width, height } = await browser.getWindowRect();
2947
3011
  return { width, height };
2948
3012
  }
@@ -2970,11 +3034,11 @@ async function keys(value) {
2970
3034
  }
2971
3035
 
2972
3036
  // src/commands/browser/mock.ts
2973
- import { getBrowserObject as getBrowserObject3 } from "@wdio/utils";
3037
+ import { getBrowserObject as getBrowserObject5 } from "@wdio/utils";
2974
3038
 
2975
3039
  // src/utils/interception/index.ts
2976
3040
  import EventEmitter2 from "node:events";
2977
- import logger5 from "@wdio/logger";
3041
+ import logger6 from "@wdio/logger";
2978
3042
  import { URLPattern } from "urlpattern-polyfill";
2979
3043
 
2980
3044
  // src/utils/Timer.ts
@@ -3140,7 +3204,7 @@ function getPatternParam(pattern, key) {
3140
3204
  }
3141
3205
 
3142
3206
  // src/utils/interception/index.ts
3143
- var log5 = logger5("WebDriverInterception");
3207
+ var log6 = logger6("WebDriverInterception");
3144
3208
  var hasSubscribedToEvents = false;
3145
3209
  var WebDriverInterception = class _WebDriverInterception {
3146
3210
  #pattern;
@@ -3169,7 +3233,7 @@ var WebDriverInterception = class _WebDriverInterception {
3169
3233
  "network.responseStarted"
3170
3234
  ]
3171
3235
  });
3172
- log5.info("subscribed to network events");
3236
+ log6.info("subscribed to network events");
3173
3237
  hasSubscribedToEvents = true;
3174
3238
  }
3175
3239
  const interception = await browser.networkAddIntercept({
@@ -3331,7 +3395,7 @@ var WebDriverInterception = class _WebDriverInterception {
3331
3395
  this.#respondOverwrites = [];
3332
3396
  this.#restored = true;
3333
3397
  const handle = await this.#browser.getWindowHandle();
3334
- log5.trace(`Restoring mock for ${handle}`);
3398
+ log6.trace(`Restoring mock for ${handle}`);
3335
3399
  SESSION_MOCKS[handle].delete(this);
3336
3400
  if (this.#mockId) {
3337
3401
  await this.#browser.networkRemoveIntercept({ intercept: this.#mockId });
@@ -3459,22 +3523,23 @@ async function mock(url6, filterOptions) {
3459
3523
  if (!this.isBidi) {
3460
3524
  throw new Error("Mocking is only supported when running tests using WebDriver Bidi");
3461
3525
  }
3462
- const browser = getBrowserObject3(this);
3463
- const handle = await browser.getWindowHandle();
3464
- if (!SESSION_MOCKS[handle]) {
3465
- SESSION_MOCKS[handle] = /* @__PURE__ */ new Set();
3526
+ const browser = getBrowserObject5(this);
3527
+ const contextManager2 = getContextManager(browser);
3528
+ const context = await contextManager2.getCurrentContext();
3529
+ if (!SESSION_MOCKS[context]) {
3530
+ SESSION_MOCKS[context] = /* @__PURE__ */ new Set();
3466
3531
  }
3467
3532
  const networkInterception = await WebDriverInterception.initiate(url6, filterOptions || {}, this);
3468
- SESSION_MOCKS[handle].add(networkInterception);
3533
+ SESSION_MOCKS[context].add(networkInterception);
3469
3534
  return networkInterception;
3470
3535
  }
3471
3536
 
3472
3537
  // src/commands/browser/mockClearAll.ts
3473
- import logger6 from "@wdio/logger";
3474
- var log6 = logger6("webdriverio:mockClearAll");
3538
+ import logger7 from "@wdio/logger";
3539
+ var log7 = logger7("webdriverio:mockClearAll");
3475
3540
  async function mockClearAll() {
3476
3541
  for (const [handle, mocks] of Object.entries(SESSION_MOCKS)) {
3477
- log6.trace(`Clearing mocks for ${handle}`);
3542
+ log7.trace(`Clearing mocks for ${handle}`);
3478
3543
  for (const mock2 of mocks) {
3479
3544
  mock2.clear();
3480
3545
  }
@@ -3482,11 +3547,11 @@ async function mockClearAll() {
3482
3547
  }
3483
3548
 
3484
3549
  // src/commands/browser/mockRestoreAll.ts
3485
- import logger7 from "@wdio/logger";
3486
- var log7 = logger7("webdriverio:mockRestoreAll");
3550
+ import logger8 from "@wdio/logger";
3551
+ var log8 = logger8("webdriverio:mockRestoreAll");
3487
3552
  async function mockRestoreAll() {
3488
3553
  for (const [handle, mocks] of Object.entries(SESSION_MOCKS)) {
3489
- log7.trace(`Clearing mocks for ${handle}`);
3554
+ log8.trace(`Clearing mocks for ${handle}`);
3490
3555
  for (const mock2 of mocks) {
3491
3556
  await mock2.restore();
3492
3557
  }
@@ -3579,19 +3644,19 @@ async function react$(selector, { props = {}, state = {} } = {}) {
3579
3644
  }
3580
3645
 
3581
3646
  // src/commands/browser/reloadSession.ts
3582
- import logger8 from "@wdio/logger";
3583
- var log8 = logger8("webdriverio");
3647
+ import logger9 from "@wdio/logger";
3648
+ var log9 = logger9("webdriverio");
3584
3649
  async function reloadSession(newCapabilities) {
3585
3650
  const oldSessionId = this.sessionId;
3586
3651
  const shutdownDriver = Boolean(newCapabilities?.browserName);
3587
3652
  try {
3588
3653
  await this.deleteSession({ shutdownDriver });
3589
3654
  } catch (err) {
3590
- log8.warn(`Suppressing error closing the session: ${err.stack}`);
3655
+ log9.warn(`Suppressing error closing the session: ${err.stack}`);
3591
3656
  }
3592
3657
  if (this.puppeteer?.connected) {
3593
3658
  this.puppeteer.disconnect();
3594
- log8.debug("Disconnected puppeteer session");
3659
+ log9.debug("Disconnected puppeteer session");
3595
3660
  }
3596
3661
  const ProtocolDriver = (await import(
3597
3662
  /* @vite-ignore */
@@ -3662,6 +3727,7 @@ async function saveRecordingScreen(filepath) {
3662
3727
 
3663
3728
  // src/commands/browser/saveScreenshot.ts
3664
3729
  import fs6 from "node:fs";
3730
+ import { getBrowserObject as getBrowserObject6 } from "@wdio/utils";
3665
3731
  async function saveScreenshot(filepath) {
3666
3732
  if (typeof filepath !== "string" || !filepath.endsWith(".png")) {
3667
3733
  throw new Error('saveScreenshot expects a filepath of type string and ".png" file ending');
@@ -3670,7 +3736,9 @@ async function saveScreenshot(filepath) {
3670
3736
  await assertDirectoryExists(absoluteFilepath);
3671
3737
  let screenBuffer;
3672
3738
  if (this.isBidi) {
3673
- const context = await this.getWindowHandle();
3739
+ const browser = getBrowserObject6(this);
3740
+ const contextManager2 = getContextManager(browser);
3741
+ const context = await contextManager2.getCurrentContext();
3674
3742
  const { data } = await this.browsingContextCaptureScreenshot({ context });
3675
3743
  screenBuffer = data;
3676
3744
  } else {
@@ -3682,11 +3750,11 @@ async function saveScreenshot(filepath) {
3682
3750
  }
3683
3751
 
3684
3752
  // src/commands/browser/scroll.ts
3685
- import logger9 from "@wdio/logger";
3686
- var log9 = logger9("webdriverio");
3753
+ import logger10 from "@wdio/logger";
3754
+ var log10 = logger10("webdriverio");
3687
3755
  function scroll(x = 0, y = 0) {
3688
3756
  if (!x && !y) {
3689
- return log9.warn('"scroll" command was called with no parameters, skipping execution');
3757
+ return log10.warn('"scroll" command was called with no parameters, skipping execution');
3690
3758
  }
3691
3759
  if (this.isMobile) {
3692
3760
  return this.execute((x2, y2) => window.scrollBy(x2, y2), x, y);
@@ -3727,7 +3795,7 @@ async function setTimeout2(timeouts) {
3727
3795
  }
3728
3796
 
3729
3797
  // src/commands/browser/setViewport.ts
3730
- import { getBrowserObject as getBrowserObject4 } from "@wdio/utils";
3798
+ import { getBrowserObject as getBrowserObject7 } from "@wdio/utils";
3731
3799
  var minWindowSize = 0;
3732
3800
  var maxWindowSize = Number.MAX_SAFE_INTEGER;
3733
3801
  async function setViewport(options) {
@@ -3740,8 +3808,9 @@ async function setViewport(options) {
3740
3808
  if (options.devicePixelRatio && (typeof options.devicePixelRatio !== "number" || options.devicePixelRatio < 0)) {
3741
3809
  throw new Error("setViewport expects devicePixelRatio to be a number in the 0 to 2^31 \u2212 1 range");
3742
3810
  }
3743
- const browser = getBrowserObject4(this);
3744
- const context = await browser.getWindowHandle();
3811
+ const browser = getBrowserObject7(this);
3812
+ const contextManager2 = getContextManager(browser);
3813
+ const context = await contextManager2.getCurrentContext();
3745
3814
  await browser.browsingContextSetViewport({
3746
3815
  context,
3747
3816
  devicePixelRatio: options.devicePixelRatio || 1,
@@ -3753,7 +3822,7 @@ async function setViewport(options) {
3753
3822
  }
3754
3823
 
3755
3824
  // src/commands/browser/setWindowSize.ts
3756
- import { getBrowserObject as getBrowserObject5 } from "@wdio/utils";
3825
+ import { getBrowserObject as getBrowserObject8 } from "@wdio/utils";
3757
3826
  var minWindowSize2 = 0;
3758
3827
  var maxWindowSize2 = Number.MAX_SAFE_INTEGER;
3759
3828
  async function setWindowSize(width, height) {
@@ -3763,7 +3832,7 @@ async function setWindowSize(width, height) {
3763
3832
  if (width < minWindowSize2 || width > maxWindowSize2 || height < minWindowSize2 || height > maxWindowSize2) {
3764
3833
  throw new Error("setWindowSize expects width and height to be a number in the 0 to 2^31 \u2212 1 range");
3765
3834
  }
3766
- const browser = getBrowserObject5(this);
3835
+ const browser = getBrowserObject8(this);
3767
3836
  await browser.setWindowRect(null, null, width, height);
3768
3837
  }
3769
3838
 
@@ -3801,12 +3870,12 @@ async function switchWindow(matcher) {
3801
3870
  }
3802
3871
 
3803
3872
  // src/commands/browser/throttle.ts
3804
- import logger10 from "@wdio/logger";
3805
- import { getBrowserObject as getBrowserObject6 } from "@wdio/utils";
3806
- var log10 = logger10("webdriverio:throttle");
3873
+ import logger11 from "@wdio/logger";
3874
+ import { getBrowserObject as getBrowserObject9 } from "@wdio/utils";
3875
+ var log11 = logger11("webdriverio:throttle");
3807
3876
  async function throttle(params) {
3808
- log10.warn('Command "throttle" is deprecated and will be removed with the next major version release! Use `throttleNetwork` instead.');
3809
- const browser = getBrowserObject6(this);
3877
+ log11.warn('Command "throttle" is deprecated and will be removed with the next major version release! Use `throttleNetwork` instead.');
3878
+ const browser = getBrowserObject9(this);
3810
3879
  await browser.throttleNetwork(params);
3811
3880
  }
3812
3881
 
@@ -3829,7 +3898,7 @@ async function throttleCPU(factor) {
3829
3898
  }
3830
3899
 
3831
3900
  // src/commands/browser/throttleNetwork.ts
3832
- import { getBrowserObject as getBrowserObject7 } from "@wdio/utils";
3901
+ import { getBrowserObject as getBrowserObject10 } from "@wdio/utils";
3833
3902
  var NETWORK_PRESETS = {
3834
3903
  "offline": {
3835
3904
  offline: true,
@@ -3906,7 +3975,7 @@ async function throttleNetwork(params) {
3906
3975
  throw new Error(`Invalid parameter for "throttleNetwork". Expected it to be typeof object or one of the following values: ${NETWORK_PRESET_TYPES.join(", ")} but found "${params}"`);
3907
3976
  }
3908
3977
  if (this.isSauce) {
3909
- const browser = getBrowserObject7(this);
3978
+ const browser = getBrowserObject10(this);
3910
3979
  await browser.sauceThrottleNetwork(params);
3911
3980
  return null;
3912
3981
  }
@@ -4058,15 +4127,15 @@ var NetworkManager = class {
4058
4127
  async initialize() {
4059
4128
  return this.#initialize;
4060
4129
  }
4061
- #beforeRequestSent(log18) {
4062
- if (log18.navigation) {
4130
+ #beforeRequestSent(log19) {
4131
+ if (log19.navigation) {
4063
4132
  return;
4064
4133
  }
4065
- const request = log18.context ? this.#requests.get(log18.context) : void 0;
4134
+ const request = log19.context ? this.#requests.get(log19.context) : void 0;
4066
4135
  if (!request) {
4067
4136
  return;
4068
4137
  }
4069
- const { request: id, headers, cookies, url: url6 } = log18.request;
4138
+ const { request: id, headers, cookies, url: url6 } = log19.request;
4070
4139
  request.children?.push({
4071
4140
  id,
4072
4141
  url: url6,
@@ -4082,66 +4151,66 @@ var NetworkManager = class {
4082
4151
  sameSite: cookie.sameSite,
4083
4152
  expiry: cookie.expiry
4084
4153
  })),
4085
- timestamp: log18.timestamp
4154
+ timestamp: log19.timestamp
4086
4155
  });
4087
4156
  }
4088
- #navigationStarted(log18) {
4157
+ #navigationStarted(log19) {
4089
4158
  if (
4090
4159
  /**
4091
4160
  * we need a navigation id to identify the request
4092
4161
  */
4093
- !log18.navigation || /**
4162
+ !log19.navigation || /**
4094
4163
  * ignore urls that do not start with http
4095
4164
  */
4096
- !log18.url.startsWith("http")
4165
+ !log19.url.startsWith("http")
4097
4166
  ) {
4098
- if (log18.navigation === null && log18.url === "") {
4099
- return this.#requests.set(log18.context, {
4167
+ if (log19.navigation === null && log19.url === "") {
4168
+ return this.#requests.set(log19.context, {
4100
4169
  url: "",
4101
4170
  headers: {},
4102
- timestamp: log18.timestamp,
4171
+ timestamp: log19.timestamp,
4103
4172
  redirectChain: [],
4104
4173
  children: []
4105
4174
  });
4106
4175
  }
4107
4176
  return;
4108
4177
  }
4109
- this.#requests.set(log18.context, {
4110
- url: log18.url,
4178
+ this.#requests.set(log19.context, {
4179
+ url: log19.url,
4111
4180
  headers: {},
4112
- timestamp: log18.timestamp,
4113
- navigation: log18.navigation,
4181
+ timestamp: log19.timestamp,
4182
+ navigation: log19.navigation,
4114
4183
  redirectChain: [],
4115
4184
  children: []
4116
4185
  });
4117
4186
  }
4118
- #fetchError(log18) {
4119
- const response = log18.context ? this.#requests.get(log18.context) : void 0;
4187
+ #fetchError(log19) {
4188
+ const response = log19.context ? this.#requests.get(log19.context) : void 0;
4120
4189
  if (!response) {
4121
4190
  return;
4122
4191
  }
4123
- const request = response.children?.find((child) => child.id === log18.request.request);
4192
+ const request = response.children?.find((child) => child.id === log19.request.request);
4124
4193
  if (!request) {
4125
4194
  return;
4126
4195
  }
4127
- request.error = log18.errorText;
4196
+ request.error = log19.errorText;
4128
4197
  }
4129
- #responseCompleted(log18) {
4130
- const response = log18.context ? this.#requests.get(log18.context) : void 0;
4198
+ #responseCompleted(log19) {
4199
+ const response = log19.context ? this.#requests.get(log19.context) : void 0;
4131
4200
  if (!response) {
4132
4201
  return;
4133
4202
  }
4134
4203
  if (!response.navigation && response.url === "") {
4135
- response.url = log18.request.url;
4136
- response.navigation = log18.navigation;
4204
+ response.url = log19.request.url;
4205
+ response.navigation = log19.navigation;
4137
4206
  }
4138
- if (log18.navigation === response.navigation) {
4139
- if (response.url !== log18.response.url) {
4207
+ if (log19.navigation === response.navigation) {
4208
+ if (response.url !== log19.response.url) {
4140
4209
  response.redirectChain?.push(response.url);
4141
4210
  }
4142
- response.url = log18.response.url;
4143
- const { headers: requestHeaders } = log18.request;
4144
- const { fromCache, headers: responseHeaders, mimeType, status } = log18.response;
4211
+ response.url = log19.response.url;
4212
+ const { headers: requestHeaders } = log19.request;
4213
+ const { fromCache, headers: responseHeaders, mimeType, status } = log19.response;
4145
4214
  response.headers = headerListToObject(requestHeaders), response.response = {
4146
4215
  fromCache,
4147
4216
  headers: headerListToObject(responseHeaders),
@@ -4150,15 +4219,15 @@ var NetworkManager = class {
4150
4219
  };
4151
4220
  return;
4152
4221
  }
4153
- const request = response.children?.find((child) => child.id === log18.request.request);
4222
+ const request = response.children?.find((child) => child.id === log19.request.request);
4154
4223
  if (!request) {
4155
4224
  return;
4156
4225
  }
4157
4226
  request.response = {
4158
- fromCache: log18.response.fromCache,
4159
- headers: headerListToObject(log18.response.headers),
4160
- mimeType: log18.response.mimeType,
4161
- status: log18.response.status
4227
+ fromCache: log19.response.fromCache,
4228
+ headers: headerListToObject(log19.response.headers),
4229
+ mimeType: log19.response.mimeType,
4230
+ status: log19.response.status
4162
4231
  };
4163
4232
  response.children?.push(request);
4164
4233
  }
@@ -4206,7 +4275,8 @@ async function url3(path4, options = {}) {
4206
4275
  }
4207
4276
  if (this.isBidi) {
4208
4277
  let resetPreloadScript;
4209
- const context = await this.getWindowHandle();
4278
+ const contextManager2 = getContextManager(this);
4279
+ const context = await contextManager2.getCurrentContext();
4210
4280
  if (options.onBeforeLoad) {
4211
4281
  if (typeof options.onBeforeLoad !== "function") {
4212
4282
  throw new Error(`Option "onBeforeLoad" must be a function, but received: ${typeof options.onBeforeLoad}`);
@@ -4363,9 +4433,9 @@ function clearValue() {
4363
4433
  }
4364
4434
 
4365
4435
  // src/commands/element/click.ts
4366
- import logger11 from "@wdio/logger";
4367
- import { getBrowserObject as getBrowserObject8 } from "@wdio/utils";
4368
- var log11 = logger11("webdriver");
4436
+ import logger12 from "@wdio/logger";
4437
+ import { getBrowserObject as getBrowserObject11 } from "@wdio/utils";
4438
+ var log12 = logger12("webdriver");
4369
4439
  function click(options) {
4370
4440
  if (typeof options !== "undefined") {
4371
4441
  if (typeof options !== "object" || Array.isArray(options)) {
@@ -4407,14 +4477,14 @@ async function actionClick(element, options) {
4407
4477
  if (!buttonValue.includes(button)) {
4408
4478
  throw new Error("Button type not supported.");
4409
4479
  }
4410
- const browser = getBrowserObject8(element);
4480
+ const browser = getBrowserObject11(element);
4411
4481
  if (x || y) {
4412
4482
  const { width, height } = await browser.getElementRect(element.elementId);
4413
4483
  if (x && x < -Math.floor(width / 2) || x && x > Math.floor(width / 2)) {
4414
- log11.warn("x would cause a out of bounds error as it goes outside of element");
4484
+ log12.warn("x would cause a out of bounds error as it goes outside of element");
4415
4485
  }
4416
4486
  if (y && y < -Math.floor(height / 2) || y && y > Math.floor(height / 2)) {
4417
- log11.warn("y would cause a out of bounds error as it goes outside of element");
4487
+ log12.warn("y would cause a out of bounds error as it goes outside of element");
4418
4488
  }
4419
4489
  }
4420
4490
  const clickNested = async () => {
@@ -4432,9 +4502,9 @@ async function actionClick(element, options) {
4432
4502
 
4433
4503
  // src/commands/element/custom$$.ts
4434
4504
  import { ELEMENT_KEY as ELEMENT_KEY8 } from "webdriver";
4435
- import { getBrowserObject as getBrowserObject9 } from "@wdio/utils";
4505
+ import { getBrowserObject as getBrowserObject12 } from "@wdio/utils";
4436
4506
  async function custom$$2(strategyName, ...strategyArguments) {
4437
- const browserObject = getBrowserObject9(this);
4507
+ const browserObject = getBrowserObject12(this);
4438
4508
  const strategy = browserObject.strategies.get(strategyName);
4439
4509
  if (!strategy) {
4440
4510
  throw Error("No strategy found for " + strategyName);
@@ -4454,9 +4524,9 @@ async function custom$$2(strategyName, ...strategyArguments) {
4454
4524
 
4455
4525
  // src/commands/element/custom$.ts
4456
4526
  import { ELEMENT_KEY as ELEMENT_KEY9 } from "webdriver";
4457
- import { getBrowserObject as getBrowserObject10 } from "@wdio/utils";
4527
+ import { getBrowserObject as getBrowserObject13 } from "@wdio/utils";
4458
4528
  async function custom$2(strategyName, ...strategyArguments) {
4459
- const browserObject = getBrowserObject10(this);
4529
+ const browserObject = getBrowserObject13(this);
4460
4530
  const strategy = browserObject.strategies.get(strategyName);
4461
4531
  if (!strategy) {
4462
4532
  throw Error("No strategy found for " + strategyName);
@@ -4476,15 +4546,15 @@ async function custom$2(strategyName, ...strategyArguments) {
4476
4546
  }
4477
4547
 
4478
4548
  // src/commands/element/doubleClick.ts
4479
- import { getBrowserObject as getBrowserObject11 } from "@wdio/utils";
4549
+ import { getBrowserObject as getBrowserObject14 } from "@wdio/utils";
4480
4550
  async function doubleClick() {
4481
- const browser = getBrowserObject11(this);
4551
+ const browser = getBrowserObject14(this);
4482
4552
  return browser.action("pointer", { parameters: { pointerType: "mouse" } }).move({ origin: this }).down().up().pause(10).down().up().perform();
4483
4553
  }
4484
4554
 
4485
4555
  // src/commands/element/dragAndDrop.ts
4486
4556
  import { ELEMENT_KEY as ELEMENT_KEY10 } from "webdriver";
4487
- import { getBrowserObject as getBrowserObject12 } from "@wdio/utils";
4557
+ import { getBrowserObject as getBrowserObject15 } from "@wdio/utils";
4488
4558
  var ACTION_BUTTON = 0;
4489
4559
  async function dragAndDrop(target, { duration = 10 } = {}) {
4490
4560
  const moveToCoordinates = target;
@@ -4510,18 +4580,21 @@ async function dragAndDrop(target, { duration = 10 } = {}) {
4510
4580
  const targetOrigin = isMovingToElement ? targetRef : "pointer";
4511
4581
  const targetX = isMovingToElement ? 0 : moveToCoordinates.x;
4512
4582
  const targetY = isMovingToElement ? 0 : moveToCoordinates.y;
4513
- const browser = getBrowserObject12(this);
4583
+ const browser = getBrowserObject15(this);
4514
4584
  return browser.action("pointer").move({ duration: 0, origin, x: 0, y: 0 }).down({ button: ACTION_BUTTON }).pause(10).move({ duration, origin: targetOrigin, x: targetX, y: targetY }).up({ button: ACTION_BUTTON }).perform();
4515
4585
  }
4516
4586
 
4517
4587
  // src/commands/element/execute.ts
4588
+ import { getBrowserObject as getBrowserObject16 } from "@wdio/utils";
4518
4589
  async function execute2(script, ...args) {
4519
4590
  if (typeof script !== "string" && typeof script !== "function") {
4520
4591
  throw new Error("number or type of arguments don't agree with execute protocol command");
4521
4592
  }
4522
4593
  if (this.isBidi) {
4523
- const context = await this.getWindowHandle();
4524
- const result = await this.scriptCallFunction({
4594
+ const browser = getBrowserObject16(this);
4595
+ const contextManager2 = getContextManager(browser);
4596
+ const context = await contextManager2.getCurrentContext();
4597
+ const result = await browser.scriptCallFunction({
4525
4598
  functionDeclaration: script.toString(),
4526
4599
  awaitPromise: false,
4527
4600
  arguments: [this, ...args].map((arg) => LocalValue.getArgument(arg)),
@@ -4538,12 +4611,15 @@ async function execute2(script, ...args) {
4538
4611
  }
4539
4612
 
4540
4613
  // src/commands/element/executeAsync.ts
4614
+ import { getBrowserObject as getBrowserObject17 } from "@wdio/utils";
4541
4615
  async function executeAsync2(script, ...args) {
4542
4616
  if (typeof script !== "string" && typeof script !== "function") {
4543
4617
  throw new Error("number or type of arguments don't agree with execute protocol command");
4544
4618
  }
4545
4619
  if (this.isBidi) {
4546
- const context = await this.getWindowHandle();
4620
+ const browser = getBrowserObject17(this);
4621
+ const contextManager2 = getContextManager(browser);
4622
+ const context = await contextManager2.getCurrentContext();
4547
4623
  const functionDeclaration = `function (...args) {
4548
4624
  return new Promise(async (resolve, reject) => {
4549
4625
  try {
@@ -4553,7 +4629,7 @@ async function executeAsync2(script, ...args) {
4553
4629
  }
4554
4630
  })
4555
4631
  }`;
4556
- const result = await this.scriptCallFunction({
4632
+ const result = await browser.scriptCallFunction({
4557
4633
  functionDeclaration,
4558
4634
  awaitPromise: true,
4559
4635
  arguments: [this, ...args].map((arg) => LocalValue.getArgument(arg)),
@@ -4576,7 +4652,7 @@ function getAttribute(attributeName) {
4576
4652
 
4577
4653
  // src/commands/element/getCSSProperty.ts
4578
4654
  import cssShorthandProps from "css-shorthand-properties";
4579
- import { getBrowserObject as getBrowserObject13 } from "@wdio/utils";
4655
+ import { getBrowserObject as getBrowserObject18 } from "@wdio/utils";
4580
4656
  async function getCSSProperty(cssProperty, pseudoElement) {
4581
4657
  const getCSSProperty2 = cssShorthandProps.isShorthand(cssProperty) ? getShorthandPropertyCSSValue : getPropertyCSSValue;
4582
4658
  const cssValue2 = await getCSSProperty2.call(
@@ -4640,7 +4716,7 @@ function mergeEqualSymmetricalValue(cssValues) {
4640
4716
  return newCssValues.join(" ");
4641
4717
  }
4642
4718
  async function getPseudoElementCSSValue(elem, options) {
4643
- const browser = getBrowserObject13(elem);
4719
+ const browser = getBrowserObject18(elem);
4644
4720
  const { cssProperty, pseudoElement } = options;
4645
4721
  const cssValue2 = await browser.execute(
4646
4722
  (elem2, pseudoElement2, cssProperty2) => window.getComputedStyle(elem2, pseudoElement2)[cssProperty2],
@@ -4669,13 +4745,13 @@ async function getElement2() {
4669
4745
  // src/commands/element/getHTML.ts
4670
4746
  import { ELEMENT_KEY as ELEMENT_KEY11 } from "webdriver";
4671
4747
  import { prettify as prettifyFn } from "htmlfy";
4672
- import { getBrowserObject as getBrowserObject14 } from "@wdio/utils";
4748
+ import { getBrowserObject as getBrowserObject19 } from "@wdio/utils";
4673
4749
 
4674
4750
  // src/shadowRoot.ts
4675
- import logger12 from "@wdio/logger";
4751
+ import logger13 from "@wdio/logger";
4676
4752
  import customElementWrapper from "./scripts/customElement.js";
4677
4753
  var shadowRootManager = /* @__PURE__ */ new Map();
4678
- var log12 = logger12("webdriverio:ShadowRootManager");
4754
+ var log13 = logger13("webdriverio:ShadowRootManager");
4679
4755
  function getShadowRootManager(browser) {
4680
4756
  const existingShadowRootManager = shadowRootManager.get(browser);
4681
4757
  if (existingShadowRootManager) {
@@ -4772,9 +4848,9 @@ var ShadowRootManager = class {
4772
4848
  !shadowElem.value?.shadowRoot?.sharedId || // we expect the shadow root to have a proper type
4773
4849
  shadowElem.value.shadowRoot.value?.nodeType !== 11
4774
4850
  ) {
4775
- return log12.warn(`Expected element with shadow root but found <${shadowElem.value?.localName} />`);
4851
+ return log13.warn(`Expected element with shadow root but found <${shadowElem.value?.localName} />`);
4776
4852
  }
4777
- log12.info(`Registered new shadow root for element <${shadowElem.value.localName} /> with id ${shadowElem.value.shadowRoot.sharedId}`);
4853
+ log13.info(`Registered new shadow root for element <${shadowElem.value.localName} /> with id ${shadowElem.value.shadowRoot.sharedId}`);
4778
4854
  const newTree = new ShadowRootTree(
4779
4855
  shadowElem.sharedId,
4780
4856
  shadowElem.value.shadowRoot.sharedId,
@@ -4919,7 +4995,7 @@ import getHTMLShadowScript from "./scripts/getHTMLShadow.js";
4919
4995
  var SHADOW_ID_ATTR_NAME = "data-wdio-shadow-id";
4920
4996
  var SHADOW_ID_ATTR = `[${SHADOW_ID_ATTR_NAME}]`;
4921
4997
  async function getHTML(options = {}) {
4922
- const browser = getBrowserObject14(this);
4998
+ const browser = getBrowserObject19(this);
4923
4999
  if (typeof options !== "object" && typeof options === "boolean") {
4924
5000
  options = { includeSelectorTag: options };
4925
5001
  } else if (typeof options !== "object") {
@@ -4950,8 +5026,9 @@ async function getHTML(options = {}) {
4950
5026
  }
4951
5027
  const { load } = await import("cheerio");
4952
5028
  const shadowRootManager2 = getShadowRootManager(browser);
4953
- const handle = await browser.getWindowHandle();
4954
- const shadowRootElementPairs = shadowRootManager2.getShadowElementPairsByContextId(handle, this.elementId);
5029
+ const contextManager2 = getContextManager(browser);
5030
+ const context = await contextManager2.getCurrentContext();
5031
+ const shadowRootElementPairs = shadowRootManager2.getShadowElementPairsByContextId(context, this.elementId);
4955
5032
  const elementsWithShadowRootAndIdVerified = (await Promise.all(
4956
5033
  shadowRootElementPairs.map(([elemId, elem]) => browser.execute((elem2) => elem2.tagName, { [ELEMENT_KEY11]: elemId }).then(
4957
5034
  () => [elemId, elem],
@@ -4972,7 +5049,7 @@ async function getHTML(options = {}) {
4972
5049
  populateHTML($3, shadowElementHTML.map(({ id, ...props }) => ({
4973
5050
  ...props,
4974
5051
  id,
4975
- mode: shadowRootManager2.getShadowRootModeById(handle, id) || "open"
5052
+ mode: shadowRootManager2.getShadowRootModeById(context, id) || "open"
4976
5053
  })));
4977
5054
  return sanitizeHTML($3, { removeCommentNodes, prettify, excludeElements });
4978
5055
  }
@@ -5063,7 +5140,7 @@ function getValue() {
5063
5140
 
5064
5141
  // src/commands/element/isClickable.ts
5065
5142
  import { ELEMENT_KEY as ELEMENT_KEY12 } from "webdriver";
5066
- import { getBrowserObject as getBrowserObject15 } from "@wdio/utils";
5143
+ import { getBrowserObject as getBrowserObject20 } from "@wdio/utils";
5067
5144
  import isElementClickableScript from "./scripts/isElementClickable.js";
5068
5145
  async function isClickable() {
5069
5146
  if (!await this.isDisplayed()) {
@@ -5072,7 +5149,7 @@ async function isClickable() {
5072
5149
  if (this.isMobile && await this.getContext().catch(() => void 0) === "NATIVE_APP") {
5073
5150
  throw new Error("Method not supported in mobile native environment. It is unlikely that you need to use this command.");
5074
5151
  }
5075
- const browser = getBrowserObject15(this);
5152
+ const browser = getBrowserObject20(this);
5076
5153
  return browser.execute(isElementClickableScript, {
5077
5154
  [ELEMENT_KEY12]: this.elementId,
5078
5155
  // w3c compatible
@@ -5082,11 +5159,11 @@ async function isClickable() {
5082
5159
  }
5083
5160
 
5084
5161
  // src/commands/element/isDisplayed.ts
5085
- import { getBrowserObject as getBrowserObject16 } from "@wdio/utils";
5162
+ import { getBrowserObject as getBrowserObject21 } from "@wdio/utils";
5086
5163
  import isElementDisplayedScript from "./scripts/isElementDisplayed.js";
5087
5164
  import isElementInViewportScript from "./scripts/isElementInViewport.js";
5088
5165
  async function isDisplayed(commandParams = { withinViewport: false }) {
5089
- const browser = getBrowserObject16(this);
5166
+ const browser = getBrowserObject21(this);
5090
5167
  if (!await hasElementId(this)) {
5091
5168
  return false;
5092
5169
  }
@@ -5113,7 +5190,7 @@ function isEnabled() {
5113
5190
 
5114
5191
  // src/commands/element/isEqual.ts
5115
5192
  import { ELEMENT_KEY as ELEMENT_KEY13 } from "webdriver";
5116
- import { getBrowserObject as getBrowserObject17 } from "@wdio/utils";
5193
+ import { getBrowserObject as getBrowserObject22 } from "@wdio/utils";
5117
5194
  var getWebElement = (el) => ({
5118
5195
  [ELEMENT_KEY13]: el.elementId,
5119
5196
  // w3c compatible
@@ -5121,7 +5198,7 @@ var getWebElement = (el) => ({
5121
5198
  // jsonwp compatible
5122
5199
  });
5123
5200
  async function isEqual(el) {
5124
- const browser = getBrowserObject17(this);
5201
+ const browser = getBrowserObject22(this);
5125
5202
  if (browser.isMobile) {
5126
5203
  const context = await browser.getContext().catch(() => void 0);
5127
5204
  const contextId = typeof context === "string" ? context : context?.id;
@@ -5159,10 +5236,10 @@ async function isExisting() {
5159
5236
 
5160
5237
  // src/commands/element/isFocused.ts
5161
5238
  import { ELEMENT_KEY as ELEMENT_KEY14 } from "webdriver";
5162
- import { getBrowserObject as getBrowserObject18 } from "@wdio/utils";
5239
+ import { getBrowserObject as getBrowserObject23 } from "@wdio/utils";
5163
5240
  import isFocusedScript from "./scripts/isFocused.js";
5164
5241
  async function isFocused() {
5165
- const browser = await getBrowserObject18(this);
5242
+ const browser = await getBrowserObject23(this);
5166
5243
  return browser.execute(isFocusedScript, {
5167
5244
  [ELEMENT_KEY14]: this.elementId,
5168
5245
  // w3c compatible
@@ -5178,10 +5255,10 @@ function isSelected() {
5178
5255
 
5179
5256
  // src/commands/element/isStable.ts
5180
5257
  import { ELEMENT_KEY as ELEMENT_KEY15 } from "webdriver";
5181
- import { getBrowserObject as getBrowserObject19 } from "@wdio/utils";
5258
+ import { getBrowserObject as getBrowserObject24 } from "@wdio/utils";
5182
5259
  import isElementStable from "./scripts/isElementStable.js";
5183
5260
  async function isStable() {
5184
- const browser = getBrowserObject19(this);
5261
+ const browser = getBrowserObject24(this);
5185
5262
  return await browser.executeAsync(isElementStable, {
5186
5263
  [ELEMENT_KEY15]: this.elementId,
5187
5264
  // w3c compatible
@@ -5191,18 +5268,18 @@ async function isStable() {
5191
5268
  }
5192
5269
 
5193
5270
  // src/commands/element/moveTo.ts
5194
- import logger13 from "@wdio/logger";
5195
- import { getBrowserObject as getBrowserObject20 } from "@wdio/utils";
5196
- var log13 = logger13("webdriver");
5271
+ import logger14 from "@wdio/logger";
5272
+ import { getBrowserObject as getBrowserObject25 } from "@wdio/utils";
5273
+ var log14 = logger14("webdriver");
5197
5274
  async function moveTo({ xOffset, yOffset } = {}) {
5198
- const browser = getBrowserObject20(this);
5275
+ const browser = getBrowserObject25(this);
5199
5276
  if (xOffset || yOffset) {
5200
5277
  const { width, height } = await browser.getElementRect(this.elementId);
5201
5278
  if (xOffset && xOffset < -Math.floor(width / 2) || xOffset && xOffset > Math.floor(width / 2)) {
5202
- log13.warn("xOffset would cause a out of bounds error as it goes outside of element");
5279
+ log14.warn("xOffset would cause a out of bounds error as it goes outside of element");
5203
5280
  }
5204
5281
  if (yOffset && yOffset < -Math.floor(height / 2) || yOffset && yOffset > Math.floor(height / 2)) {
5205
- log13.warn("yOffset would cause a out of bounds error as it goes outside of element");
5282
+ log14.warn("yOffset would cause a out of bounds error as it goes outside of element");
5206
5283
  }
5207
5284
  }
5208
5285
  const moveToNested = async () => {
@@ -5250,7 +5327,7 @@ function previousElement() {
5250
5327
  import fs8 from "node:fs/promises";
5251
5328
  import url4 from "node:url";
5252
5329
  import { resolve as resolve3 } from "import-meta-resolve";
5253
- import { getBrowserObject as getBrowserObject21 } from "@wdio/utils";
5330
+ import { getBrowserObject as getBrowserObject26 } from "@wdio/utils";
5254
5331
  import { waitToLoadReact as waitToLoadReact3, react$$ as react$$Script2 } from "./scripts/resq.js";
5255
5332
  var resqScript3;
5256
5333
  async function react$$2(selector, { props = {}, state = {} } = {}) {
@@ -5258,7 +5335,7 @@ async function react$$2(selector, { props = {}, state = {} } = {}) {
5258
5335
  const resqScriptPath = url4.fileURLToPath(await resolve3("resq", import.meta.url));
5259
5336
  resqScript3 = (await fs8.readFile(resqScriptPath)).toString();
5260
5337
  }
5261
- const browser = await getBrowserObject21(this);
5338
+ const browser = await getBrowserObject26(this);
5262
5339
  await this.executeScript(resqScript3.toString(), []);
5263
5340
  await browser.execute(waitToLoadReact3);
5264
5341
  const res = await browser.execute(
@@ -5276,7 +5353,7 @@ async function react$$2(selector, { props = {}, state = {} } = {}) {
5276
5353
  import fs9 from "node:fs/promises";
5277
5354
  import url5 from "node:url";
5278
5355
  import { resolve as resolve4 } from "import-meta-resolve";
5279
- import { getBrowserObject as getBrowserObject22 } from "@wdio/utils";
5356
+ import { getBrowserObject as getBrowserObject27 } from "@wdio/utils";
5280
5357
  import { waitToLoadReact as waitToLoadReact4, react$ as react$Script2 } from "./scripts/resq.js";
5281
5358
  var resqScript4;
5282
5359
  async function react$2(selector, { props = {}, state = {} } = {}) {
@@ -5284,7 +5361,7 @@ async function react$2(selector, { props = {}, state = {} } = {}) {
5284
5361
  const resqScriptPath = url5.fileURLToPath(await resolve4("resq", import.meta.url));
5285
5362
  resqScript4 = (await fs9.readFile(resqScriptPath)).toString();
5286
5363
  }
5287
- const browser = await getBrowserObject22(this);
5364
+ const browser = await getBrowserObject27(this);
5288
5365
  await this.executeScript(resqScript4.toString(), []);
5289
5366
  await browser.execute(waitToLoadReact4);
5290
5367
  const res = await browser.execute(
@@ -5312,12 +5389,12 @@ async function saveScreenshot2(filepath) {
5312
5389
  }
5313
5390
 
5314
5391
  // src/commands/element/scrollIntoView.ts
5315
- import logger14 from "@wdio/logger";
5392
+ import logger15 from "@wdio/logger";
5316
5393
  import { ELEMENT_KEY as ELEMENT_KEY16 } from "webdriver";
5317
- import { getBrowserObject as getBrowserObject23 } from "@wdio/utils";
5318
- var log14 = logger14("webdriverio");
5394
+ import { getBrowserObject as getBrowserObject28 } from "@wdio/utils";
5395
+ var log15 = logger15("webdriverio");
5319
5396
  function scrollIntoViewWeb(options = { block: "start", inline: "nearest" }) {
5320
- const browser = getBrowserObject23(this);
5397
+ const browser = getBrowserObject28(this);
5321
5398
  return browser.execute(
5322
5399
  (elem, options2) => elem.scrollIntoView(options2),
5323
5400
  {
@@ -5330,7 +5407,7 @@ function scrollIntoViewWeb(options = { block: "start", inline: "nearest" }) {
5330
5407
  );
5331
5408
  }
5332
5409
  async function scrollIntoView(options = { block: "start", inline: "nearest" }) {
5333
- const browser = getBrowserObject23(this);
5410
+ const browser = getBrowserObject28(this);
5334
5411
  if (browser.isMobile) {
5335
5412
  return scrollIntoViewWeb.call(this, options);
5336
5413
  }
@@ -5374,7 +5451,7 @@ async function scrollIntoView(options = { block: "start", inline: "nearest" }) {
5374
5451
  deltaY = Math.round(deltaY - scrollY);
5375
5452
  await browser.action("wheel").scroll({ duration: 0, x: deltaX, y: deltaY, origin: this }).perform();
5376
5453
  } catch (err) {
5377
- log14.warn(
5454
+ log15.warn(
5378
5455
  `Failed to execute "scrollIntoView" using WebDriver Actions API: ${err.message}!
5379
5456
  Re-attempting using \`Element.scrollIntoView\` via Web API.`
5380
5457
  );
@@ -5439,8 +5516,8 @@ async function setValue(value) {
5439
5516
  }
5440
5517
 
5441
5518
  // src/commands/element/shadow$$.ts
5442
- import logger15 from "@wdio/logger";
5443
- import { getBrowserObject as getBrowserObject24 } from "@wdio/utils";
5519
+ import logger16 from "@wdio/logger";
5520
+ import { getBrowserObject as getBrowserObject29 } from "@wdio/utils";
5444
5521
  import { SHADOW_ELEMENT_KEY } from "webdriver";
5445
5522
  import { shadowFnFactory } from "./scripts/shadowFnFactory.js";
5446
5523
 
@@ -5766,9 +5843,9 @@ var createRoleBaseXpathSelector = (role) => {
5766
5843
  };
5767
5844
 
5768
5845
  // src/commands/element/shadow$$.ts
5769
- var log15 = logger15("webdriverio");
5846
+ var log16 = logger16("webdriverio");
5770
5847
  async function shadow$$(selector) {
5771
- const browser = getBrowserObject24(this);
5848
+ const browser = getBrowserObject29(this);
5772
5849
  try {
5773
5850
  const shadowRoot = await browser.getElementShadowRoot(this.elementId);
5774
5851
  const { using, value } = findStrategy(selector, this.isW3C, this.isMobile);
@@ -5776,7 +5853,7 @@ async function shadow$$(selector) {
5776
5853
  const elements = await getElements.call(this, selector, res, { isShadowElement: true });
5777
5854
  return enhanceElementsArray(elements, this, selector);
5778
5855
  } catch (err) {
5779
- log15.warn(
5856
+ log16.warn(
5780
5857
  `Failed to fetch element within shadow DOM using WebDriver command: ${err.message}!
5781
5858
  Falling back to JavaScript shim.`
5782
5859
  );
@@ -5785,20 +5862,20 @@ Falling back to JavaScript shim.`
5785
5862
  }
5786
5863
 
5787
5864
  // src/commands/element/shadow$.ts
5788
- import logger16 from "@wdio/logger";
5865
+ import logger17 from "@wdio/logger";
5789
5866
  import { SHADOW_ELEMENT_KEY as SHADOW_ELEMENT_KEY2 } from "webdriver";
5790
5867
  import { shadowFnFactory as shadowFnFactory2 } from "./scripts/shadowFnFactory.js";
5791
- import { getBrowserObject as getBrowserObject25 } from "@wdio/utils";
5792
- var log16 = logger16("webdriverio");
5868
+ import { getBrowserObject as getBrowserObject30 } from "@wdio/utils";
5869
+ var log17 = logger17("webdriverio");
5793
5870
  async function shadow$(selector) {
5794
- const browser = getBrowserObject25(this);
5871
+ const browser = getBrowserObject30(this);
5795
5872
  try {
5796
5873
  const shadowRoot = await browser.getElementShadowRoot(this.elementId);
5797
5874
  const { using, value } = findStrategy(selector, this.isW3C, this.isMobile);
5798
5875
  const res = await browser.findElementFromShadowRoot(shadowRoot[SHADOW_ELEMENT_KEY2], using, value);
5799
5876
  return getElement.call(this, selector, res, { isShadowElement: true });
5800
5877
  } catch (err) {
5801
- log16.warn(
5878
+ log17.warn(
5802
5879
  `Failed to fetch element within shadow DOM using WebDriver command: ${err.message}!
5803
5880
  Falling back to JavaScript shim.`
5804
5881
  );
@@ -6097,7 +6174,7 @@ function querySelectorAllDeep(findMany, s, r) {
6097
6174
  }
6098
6175
 
6099
6176
  // src/utils/index.ts
6100
- var log17 = logger17("webdriverio");
6177
+ var log18 = logger18("webdriverio");
6101
6178
  var INVALID_SELECTOR_ERROR = "selector needs to be typeof `string` or `function`";
6102
6179
  var IGNORED_COMMAND_FILE_EXPORTS = ["SESSION_MOCKS", "CDP_SESSIONS"];
6103
6180
  var scopes = {
@@ -6191,7 +6268,7 @@ function fetchElementByJSFunction(selector, scope, referenceId) {
6191
6268
  if (referenceId) {
6192
6269
  args.push(referenceId);
6193
6270
  }
6194
- return getBrowserObject26(scope).executeScript(`return (${script}).apply(null, arguments)`, args);
6271
+ return getBrowserObject31(scope).executeScript(`return (${script}).apply(null, arguments)`, args);
6195
6272
  }
6196
6273
  function isElement(o) {
6197
6274
  return typeof HTMLElement === "object" ? o instanceof HTMLElement : o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string";
@@ -6221,9 +6298,10 @@ function transformClassicToBidiSelector(using, value) {
6221
6298
  throw new Error(`Can't transform classic selector ${using} to Bidi selector`);
6222
6299
  }
6223
6300
  async function findDeepElement(selector) {
6224
- const browser = getBrowserObject26(this);
6301
+ const browser = getBrowserObject31(this);
6225
6302
  const shadowRootManager2 = getShadowRootManager(browser);
6226
- const context = await browser.getWindowHandle();
6303
+ const contextManager2 = getContextManager(browser);
6304
+ const context = await contextManager2.getCurrentContext();
6227
6305
  const shadowRoots = shadowRootManager2.getShadowElementsByContextId(
6228
6306
  context,
6229
6307
  this.elementId
@@ -6249,7 +6327,7 @@ async function findDeepElement(selector) {
6249
6327
  })).then((elems) => elems.filter(([isIn]) => isIn).map(([, elem]) => elem));
6250
6328
  return scopedNodes[0];
6251
6329
  }, (err) => {
6252
- log17.warn(`Failed to execute browser.browsingContextLocateNodes({ ... }) due to ${err}, falling back to regular WebDriver Classic command`);
6330
+ log18.warn(`Failed to execute browser.browsingContextLocateNodes({ ... }) due to ${err}, falling back to regular WebDriver Classic command`);
6253
6331
  return browser.findElement(using, value);
6254
6332
  });
6255
6333
  if (!deepElementResult) {
@@ -6258,9 +6336,10 @@ async function findDeepElement(selector) {
6258
6336
  return deepElementResult;
6259
6337
  }
6260
6338
  async function findDeepElements(selector) {
6261
- const browser = getBrowserObject26(this);
6339
+ const browser = getBrowserObject31(this);
6262
6340
  const shadowRootManager2 = getShadowRootManager(browser);
6263
- const context = await browser.getWindowHandle();
6341
+ const contextManager2 = getContextManager(browser);
6342
+ const context = await contextManager2.getCurrentContext();
6264
6343
  const shadowRoots = shadowRootManager2.getShadowElementsByContextId(
6265
6344
  context,
6266
6345
  this.elementId
@@ -6286,13 +6365,13 @@ async function findDeepElements(selector) {
6286
6365
  })).then((elems) => elems.filter(([isIn]) => isIn).map(([, elem]) => elem));
6287
6366
  return scopedNodes;
6288
6367
  }, (err) => {
6289
- log17.warn(`Failed to execute browser.browsingContextLocateNodes({ ... }) due to ${err}, falling back to regular WebDriver Classic command`);
6368
+ log18.warn(`Failed to execute browser.browsingContextLocateNodes({ ... }) due to ${err}, falling back to regular WebDriver Classic command`);
6290
6369
  return browser.findElements(using, value);
6291
6370
  });
6292
6371
  return deepElementResult;
6293
6372
  }
6294
6373
  async function findElement2(selector) {
6295
- const browserObject = getBrowserObject26(this);
6374
+ const browserObject = getBrowserObject31(this);
6296
6375
  const shadowRootManager2 = getShadowRootManager(browserObject);
6297
6376
  if (this.isBidi && typeof selector === "string" && !selector.startsWith(DEEP_SELECTOR) && !shadowRootManager2.isWithinFrame()) {
6298
6377
  return findDeepElement.call(this, selector);
@@ -6346,7 +6425,7 @@ async function findElement2(selector) {
6346
6425
  throw new Error(`${INVALID_SELECTOR_ERROR}, but found: \`${typeof selector}\``);
6347
6426
  }
6348
6427
  async function findElements(selector) {
6349
- const browserObject = getBrowserObject26(this);
6428
+ const browserObject = getBrowserObject31(this);
6350
6429
  if (typeof selector === "string" && selector.startsWith(DEEP_SELECTOR)) {
6351
6430
  const elems = await browserObject.execute(
6352
6431
  `return (${querySelectorAllDeep}).apply(null, arguments)`,
@@ -6395,7 +6474,7 @@ async function getElementRect(scope) {
6395
6474
  const rect = await scope.getElementRect(scope.elementId);
6396
6475
  const defaults = { x: 0, y: 0, width: 0, height: 0 };
6397
6476
  if (Object.keys(defaults).some((key) => rect[key] === void 0)) {
6398
- const rectJs = await getBrowserObject26(scope).execute(function(el) {
6477
+ const rectJs = await getBrowserObject31(scope).execute(function(el) {
6399
6478
  if (!el || !el.getBoundingClientRect) {
6400
6479
  return;
6401
6480
  }
@@ -6414,7 +6493,7 @@ async function getElementRect(scope) {
6414
6493
  if (rectJs && typeof rectJs[key] === "number") {
6415
6494
  rect[key] = Math.floor(rectJs[key]);
6416
6495
  } else {
6417
- log17.error("getElementRect", { rect, rectJs, key });
6496
+ log18.error("getElementRect", { rect, rectJs, key });
6418
6497
  throw new Error("Failed to receive element rects via execute command");
6419
6498
  }
6420
6499
  });
@@ -6492,7 +6571,7 @@ var elementErrorHandler = (fn) => (commandName, commandFn) => {
6492
6571
  this[ELEMENT_KEY18] = element.elementId;
6493
6572
  try {
6494
6573
  const result = await fn(commandName, commandFn).apply(this, args);
6495
- const caps = getBrowserObject27(this).capabilities;
6574
+ const caps = getBrowserObject32(this).capabilities;
6496
6575
  if (caps?.browserName === "safari" && result?.error === "no such element") {
6497
6576
  const errorName = "stale element reference";
6498
6577
  const err = new Error(errorName);
@@ -6881,14 +6960,14 @@ var DialogManager = class {
6881
6960
  /**
6882
6961
  * capture shadow root elements propagated through console.debug
6883
6962
  */
6884
- async #handleUserPrompt(log18) {
6963
+ async #handleUserPrompt(log19) {
6885
6964
  if (this.#autoHandleDialog) {
6886
6965
  return this.#browser.browsingContextHandleUserPrompt({
6887
6966
  accept: false,
6888
- context: log18.context
6967
+ context: log19.context
6889
6968
  });
6890
6969
  }
6891
- const dialog = new Dialog(log18, this.#browser);
6970
+ const dialog = new Dialog(log19, this.#browser);
6892
6971
  this.#browser.emit("dialog", dialog);
6893
6972
  }
6894
6973
  /**
@@ -6951,7 +7030,7 @@ var remote = async function(params, remoteModifier) {
6951
7030
  const keysToKeep = Object.keys(process.env.WDIO_WORKER_ID ? params : DEFAULTS);
6952
7031
  const config = validateConfig(WDIO_DEFAULTS, params, keysToKeep);
6953
7032
  await enableFileLogging(config.outputDir);
6954
- logger18.setLogLevelsConfig(config.logLevels, config.logLevel);
7033
+ logger19.setLogLevelsConfig(config.logLevels, config.logLevel);
6955
7034
  const modifier = (client, options2) => {
6956
7035
  Object.assign(options2, Object.entries(config).reduce((a, [k, v]) => typeof v === "undefined" ? a : { ...a, [k]: v }, {}));
6957
7036
  if (typeof remoteModifier === "function") {
@@ -6972,7 +7051,8 @@ var remote = async function(params, remoteModifier) {
6972
7051
  await Promise.all([
6973
7052
  getShadowRootManager(instance).initialize(),
6974
7053
  getNetworkManager(instance).initialize(),
6975
- getDialogManager(instance).initialize()
7054
+ getDialogManager(instance).initialize(),
7055
+ getContextManager(instance).initialize()
6976
7056
  ]);
6977
7057
  return instance;
6978
7058
  };
@@ -6996,7 +7076,8 @@ var attach = async function(attachOptions) {
6996
7076
  await driver._bidiHandler?.connect().then(() => Promise.all([
6997
7077
  getShadowRootManager(driver).initialize(),
6998
7078
  getNetworkManager(driver).initialize(),
6999
- getDialogManager(driver).initialize()
7079
+ getDialogManager(driver).initialize(),
7080
+ getContextManager(driver).initialize()
7000
7081
  ]));
7001
7082
  return driver;
7002
7083
  };