Skip to content

[🐛 Bug]: WDIO v9 breaks backwards compatibility of executeAsync when used with BiDi #13443

@Zidious

Description

@Zidious

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

20

Mode

WDIO Testrunner

Which capabilities are you using?

capabilities: [
    {
      // capabilities for local browser web tests
      browserName: "chrome",
      // "wdio:enforceWebDriverClassic": true, - toggled on to check usage differences
    },
  ]

What happened?

Toggling wdio:enforceWebDriverClassic or using v8 passing a statement string to browser.executeAsync executes as expected, example:

const res = await browser.executeAsync(`
    const callback = arguments[arguments.length - 1];
    return Promise.resolve(arguments[0] * 2).then(callback);
`, 6);

console.log({ res }); // 12

When using WDIO v9 which defaults to use the BiDi protocol, I get an error:

[0-0] 2024-08-23T17:36:47.136Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[391 bytes]>","awaitPromise":true,"arguments":[{"type":"number","value":6}],"target":{"context":"C510048CD98884A967DA0A57E837406F"}}
[0-0] {
[0-0]   res: {
[0-0]     error: {
[0-0]       message: "SyntaxError: Unexpected token 'const'",
[0-0]       columnNumber: 26,
[0-0]       exception: [Object],
[0-0]       lineNumber: 9,
[0-0]       stackTrace: [Object]
[0-0]     }
[0-0]   }
[0-0] }

To get around this I've had to replace my string with a function:

const res = await browser.executeAsync(function myFunc(...args: any[]) {
  return Promise.resolve(args[0] * 2).then(args[args.length - 1]);
}, 6);

console.log({ res }); // 12

This appears to have been introduced in: #13389

What is your expected behavior?

browser.executeAsync Function to execute as expected regardless if passed as a string or function declaration.

How to reproduce the bug.

With WDIO v9 use:

const res = await browser.executeAsync(`
    const callback = arguments[arguments.length - 1];
    return Promise.resolve(arguments[0] * 2).then(callback);
`, 6);

console.log({ res }); // 12

Relevant log output

[0-0] 2024-08-23T17:36:47.136Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[391 bytes]>","awaitPromise":true,"arguments":[{"type":"number","value":6}],"target":{"context":"C510048CD98884A967DA0A57E837406F"}}
[0-0] {
[0-0]   res: {
[0-0]     error: {
[0-0]       message: "SyntaxError: Unexpected token 'const'",
[0-0]       columnNumber: 26,
[0-0]       exception: [Object],
[0-0]       lineNumber: 9,
[0-0]       stackTrace: [Object]
[0-0]     }
[0-0]   }
[0-0] }


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

### Is there an existing issue for this?

- [X] I have searched the existing issues

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions