-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
latest (9.21.1)
Node.js Version
22.21.1
Mode
WDIO Testrunner
Which capabilities are you using?
capabilities: [
{
"bstack:options": {
os: 'Windows',
osVersion: '11',
seleniumVersion: '4.35.0',
seleniumBidi: 'true',
projectName: "ProjectName",
buildName: "BuildName",
sessionName: "SessionName",
debug: "true",
networkLogs: "true",
consoleLogs: "verbose",
},
browserName: 'chrome',
browserVersion: 'latest',
} as Capabilities.BrowserStackCapabilities,What happened?
The performO11ySync function in @wdio/browserstack-service throws a SyntaxError when attempting to sync observability data during test execution, particularly during session cleanup or when explicitly exiting the process.
Error Message:
[0-0] SYNCHRONOUS TERMINATION NOTICE: When explicitly exiting the process via process.exit or via a parent process, asynchronous tasks in your exitHooks will not run. Either remove these tasks, use gracefulExit() instead of process.exit(), or ensure your parent process sends a SIGINT to the process running this code.
[0-0] <anonymous_script>:3
[0-0] browserstack_executor: {"action":"annotate","arguments":{"data":"ObservabilitySync:1765200172514","level":"debug"}}
[0-0] ^
[0-0]
[0-0] SyntaxError: Unexpected token ':'
[0-0] at new Function ()
[0-0] at Browser.execute (C:\Projects...\node_modules\webdriverio\build\node.js:3571:53)
[0-0] at async performO11ySync (C:\Projects...\node_modules@wdio\browserstack-service\build\index.js:2601:5)
Invalid JavaScript syntax: The function attempts to execute the following string in the browser:
browserstack_executor: {"action":"annotate","arguments":{...}}
This is not valid JavaScript syntax. It appears to be a label followed by an object literal, which cannot be executed in Chrome with bidi enabled.
What is your expected behavior?
A temporary workaround that solved the issue for me was to adjust the method here - https://github.com/webdriverio/webdriverio/blob/main/packages/wdio-browserstack-service/src/util.ts#L1830
from:
export const performO11ySync = async (browser: WebdriverIO.Browser) => {
if (isBrowserstackSession(browser)) {
await browser.execute(`browserstack_executor: ${JSON.stringify({
action: 'annotate',
arguments: {
data: `ObservabilitySync:${Date.now()}`,
level: 'debug'
}
})}`)
}
}
to:
export const performO11ySync = async (browser: WebdriverIO.Browser) => {
try {
await browser.execute(
(data) => {
if (typeof (window as any).browserstack_executor === 'function') {
(window as any).browserstack_executor(data)
}
},
{
action: 'annotate',
arguments: {
data: `ObservabilitySync:${Date.now()}`,
level: 'debug'
}
}
)
} catch {
// Ingore the error for now
}
}
Disabling testObservability also works but I would not consider that to be fix because you lose the observability features tied to it.
How to reproduce the bug.
Run any test with the capabilities mentioned above, don't forget to set seleniumBidi: 'true'
Relevant log output
[0-0] SyntaxError: Unexpected token ':'
[0-0] at new Function (<anonymous>)
[0-0] at Browser.execute (C:\Projects\...\node_modules\webdriverio\build\node.js:3571:53)
[0-0] at async performO11ySync (C:\Projects\...\node_modules\@wdio\browserstack-service\build\index.js:2601:5)Code of Conduct
- I agree to follow this project's Code of Conduct
Is there an existing issue for this?
- I have searched the existing issues