Skip to content

[🐛 Bug]: browser execute API return an error: __name is not defined #13671

@lacell75

Description

@lacell75

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.1.2

Node.js Version

20

Mode

Standalone Mode

Which capabilities are you using?

{
        browserName: 'chrome',
       'wdio:enforceWebDriverClassic': true,
}

What happened?

With enforceWebDriverClassic capability, browser.execute doesn't work correctly with scripts in parameter.

await browser.execute(script.start);

What is your expected behavior?

No error

How to reproduce the bug.

To reproduce this bug

git clone https://github.com/lacell75/cucumber-boilerplate.git
git checkout executeError  (https://github.com/lacell75/cucumber-boilerplate/tree/executeError)
yarn install
npx wdio wdio.conf.ts --spec ./src/features/execute.feature

Relevant log output

javascript error: WebDriverError: javascript error: __name is not defined
  (Session info: chrome=129.0.6668.60) when running "execute/sync" with method "POST" and args "function start(){const nAMESPACE="toasts";window[nAMESPACE]={[nAMESPACE]:[]};if(window.sessionStorage?.removeItem){window.sessionStorage.removeItem(nAMESPACE)}function pushToSessionStorage(toast){if(!window.sessionStorage?.setItem){return}const rawData=window.sessionStorage.getItem(nAMESPACE);let parsed;if(rawData){try{parsed=JSON.parse(rawData)}catch(error){throw new Error(`Could not parse sessionStorage data: ${error.message}`)}}else{parsed=[]}if(!parsed.includes(toast))parsed.push(toast);window.sessionStorage.setItem(nAMESPACE,JSON.stringify(parsed))}__name(pushToSessionStorage,"pushToSessionStorage");function addToast(toast){toast=toast.replaceAll(/\s{2,}/gi," ").replace(" ","");if(!window[nAMESPACE].toasts.includes(toast))window[nAMESPACE].toasts.push(toast);pushToSessionStorage(toast)}__name(addToast,"addToast");function getNotificationText(){const alerts=document?.querySelectorAll("sl-alert");alerts.forEach(alert=>{const testContext=alert?.textContent;if(testContext){addToast(testContext)}})}__name(getNotificationText,"getNotificationText");getNotificationText();setInterval(getNotificationText,2500);console.log("Toast Interceptor started")}"
    at FetchRequest._request (C:\2-gitlab\cucumber-boilerplate\node_modules\webdriver\build\index.js:1350:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Browser.wrapCommandFn (C:\2-gitlab\cucumber-boilerplate\node_modules\@wdio\utils\build\index.js:1380:23)     
    at async Browser.wrapCommandFn (C:\2-gitlab\cucumber-boilerplate\node_modules\@wdio\utils\build\index.js:1380:23)     
    at async World.<anonymous> (C:\2-gitlab\cucumber-boilerplate\src\steps\given.ts:32:5)


### 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