-
-
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
Node.js Version
20
Mode
Standalone Mode
Which capabilities are you using?
{
browserName: 'chrome',
browserVersion: '136'
}What happened?
The screenshots are not processed normally.
Currently, we use a regex to check if a given string matches a valid format (e.g., Base64). This works well for smaller strings. However, when the input string is very large (over ~4053844 characters), the regex engine struggles — likely due to performance or internal engine limitations.
The error stack we get:
RangeError: Maximum call stack size exceeded
at RegExp.test ()
at #handleResponse (file:///Users/nikolaoslytras/work/wdio_v9/node_modules/webdriver/build/node.js:450:150)
at WebSocket.emit (node:events:530:35)
at WebSocket.emit (node:domain:488:12)
at Receiver.receiverOnMessage (/Users/nikolaoslytras/work/wdio_v9/node_modules/ws/lib/websocket.js:1220:20)
at Receiver.emit (node:events:518:28)
at Receiver.emit (node:domain:488:12)
at Receiver.dataMessage (/Users/nikolaoslytras/work/wdio_v9/node_modules/ws/lib/receiver.js:596:14)
at /Users/nikolaoslytras/work/wdio_v9/node_modules/ws/lib/receiver.js:530:12
at /Users/nikolaoslytras/work/wdio_v9/node_modules/ws/lib/permessage-deflate.js:309:9
Suggested Fix:
Introduce a dynamic chunking mechanism based on the total string length — for example, derive the number of chunks from the length itself. This makes the solution more scalable for very large strings, even in the millions of characters range.
What is your expected behavior?
The expected behavior is for the screenshot to be processed normally.
How to reproduce the bug.
To reproduce the issue, you can try taking a screenshot using either the Visual Service’s checkScreen method or the browsingContextCaptureScreenshot function provided by WDIO. Use an image that contains a high level of visual detail, as this will generate a very large Base64 string.
You can also refer to the following repository for a ready-made example:
👉 https://github.com/gromanas/wdio_v9 (bidi-issue branch)
It contains both a working and a non-working screenshot to illustrate the problem.
Relevant log output
2025-05-16T13:45:40.412Z INFO webdriver: Initiate new session using the WebDriver protocol
index.js:912025-05-16T13:45:40.532Z INFO webdriver: Using Chromedriver v136.0.7103.114 from cache directory /var/folders/2n/b8wjvxm93r71688x4gb3g9_w0000gn/T
index.js:912025-05-16T13:45:40.546Z INFO chromedriver: Starting ChromeDriver 136.0.7103.114 (cedfcc36d433dba0d681ec32e86b8d0593fc820c-refs/branch-heads/7103_108@{#4}) on port 59195
index.js:912025-05-16T13:45:40.546Z INFO chromedriver: Remote connections are allowed by an allowlist (0.0.0.0).
index.js:912025-05-16T13:45:40.546Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
index.js:912025-05-16T13:45:40.562Z INFO chromedriver: ChromeDriver was started successfully on port 59195.
index.js:912025-05-16T13:45:40.641Z INFO @wdio/utils: Started Chromedriver v136.0.7103.114 with params --port=59195 --allowed-origins=* --allowed-ips=0.0.0.0 in 144ms on port 59195
index.js:912025-05-16T13:45:40.654Z INFO webdriver: [POST] http://localhost:59195/session
index.js:912025-05-16T13:45:40.654Z INFO webdriver: DATA
Object {capabilities: {…}}
index.js:912025-05-16T13:45:41.599Z INFO webdriver: Register BiDi handler for session with id cf0e5e20ab09299d9b18d0e09615d642
index.js:912025-05-16T13:45:41.599Z INFO webdriver: Connecting to webSocketUrl ws://127.0.0.1:59195/session/cf0e5e20ab09299d9b18d0e09615d642
index.js:912025-05-16T13:45:41.601Z DEBUG webdriver: Attempt to connect to webSocketUrl ws://127.0.0.1:59195/session/cf0e5e20ab09299d9b18d0e09615d642
index.js:912025-05-16T13:45:41.605Z INFO webdriver: Connected to Bidi protocol at ws://127.0.0.1:59195/session/cf0e5e20ab09299d9b18d0e09615d642
index.js:912025-05-16T13:45:41.605Z INFO webdriver: Connected to WebDriver Bidi interface at ws://127.0.0.1:59195/session/cf0e5e20ab09299d9b18d0e09615d642
index.js:912025-05-16T13:45:41.605Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.contextCreated"]}
index.js:912025-05-16T13:45:41.606Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["log.entryAdded","browsingContext.navigationStarted"]}
index.js:912025-05-16T13:45:41.606Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[1319 bytes]>, contexts: undefined }
index.js:912025-05-16T13:45:41.607Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted","browsingContext.fragmentNavigated","network.responseCompleted","network.beforeRequestSent","network.fetchError"]}
index.js:912025-05-16T13:45:41.607Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.userPromptOpened"]}
index.js:912025-05-16T13:45:41.607Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted"]}
index.js:912025-05-16T13:45:41.607Z INFO webdriver: COMMAND getWindowHandle()
index.js:912025-05-16T13:45:41.608Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
index.js:912025-05-16T13:45:41.608Z INFO webdriver: [GET] http://localhost:59195/session/cf0e5e20ab09299d9b18d0e09615d642/window
index.js:912025-05-16T13:45:41.611Z INFO webdriver: RESULT ED0880FB0989BAD969B76D529C016D49
index.js:912025-05-16T13:45:41.612Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id ED0880FB0989BAD969B76D529C016D49
index.js:912025-05-16T13:45:41.613Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[442 bytes] webdriverioPolyfill>","target":{"children":null,"clientWindow":"1579773110","context":"ED0880FB0989BAD969B76D529C016D49","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"},"awaitPromise":false}
index.js:912025-05-16T13:45:41.613Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[442 bytes]>, contexts: ["ED0880FB0989BAD969B76D529C016D49"] }
index.js:912025-05-16T13:45:41.613Z INFO webdriver: BIDI RESULT {"id":1,"result":{"subscription":"63ef4476-6c77-4538-8128-2277158972ed"},"type":"success"}
index.js:912025-05-16T13:45:41.614Z INFO webdriver: BIDI RESULT {"id":2,"result":{"subscription":"3f6e4255-f29a-4262-b4fe-18080aff0cfe"},"type":"success"}
index.js:912025-05-16T13:45:41.614Z INFO webdriver: BIDI RESULT {"id":4,"result":{"subscription":"fb27ca05-ce45-49a5-9be9-e55a5f06289c"},"type":"success"}
index.js:912025-05-16T13:45:41.614Z INFO webdriver: BIDI RESULT {"id":5,"result":{"subscription":"b0afd68a-66bd-484e-a3a1-b9f64e816842"},"type":"success"}
index.js:912025-05-16T13:45:41.615Z INFO webdriver: BIDI RESULT {"id":3,"result":{"script":"c4321e25-2c0b-4381-914a-e1af524a9bb0"},"type":"success"}
index.js:912025-05-16T13:45:41.615Z INFO webdriver: BIDI RESULT {"id":6,"result":{"subscription":"3935c6b5-1efe-4fe2-81c4-56935f53ce10"},"type":"success"}
index.js:912025-05-16T13:45:41.615Z INFO webdriver: BIDI RESULT {"id":7,"result":{"contexts":[{"children":[],"clientWindow":"1579773110","context":"ED0880FB0989BAD969B76D529C016D49","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"}]},"type":"success"}
index.js:912025-05-16T13:45:41.616Z INFO @wdio/visual-service: Adding commands to global browser
index.js:912025-05-16T13:45:41.616Z INFO @wdio/visual-service: Adding element command "saveElement" to browser object
index.js:912025-05-16T13:45:41.616Z INFO @wdio/visual-service: Adding element command "checkElement" to browser object
index.js:912025-05-16T13:45:41.616Z INFO @wdio/visual-service: Adding browser command "saveScreen" to browser object
index.js:912025-05-16T13:45:41.616Z INFO @wdio/visual-service: Adding browser command "saveFullPageScreen" to browser object
index.js:912025-05-16T13:45:41.616Z INFO @wdio/visual-service: Adding browser command "saveTabbablePage" to browser object
index.js:912025-05-16T13:45:41.616Z INFO @wdio/visual-service: Adding browser command "checkScreen" to browser object
index.js:912025-05-16T13:45:41.617Z INFO @wdio/visual-service: Adding browser command "checkFullPageScreen" to browser object
index.js:912025-05-16T13:45:41.617Z INFO @wdio/visual-service: Adding browser command "checkTabbablePage" to browser object
index.js:912025-05-16T13:45:41.617Z INFO @wdio/visual-service: Adding browser command "waitForStorybookComponentToBeLoaded" to browser object
index.js:912025-05-16T13:45:41.617Z DEBUG @wdio/utils:shim: Finished to run "before" hook in 1ms
index.js:912025-05-16T13:45:41.619Z INFO webdriver: BIDI COMMAND browsingContext.setViewport {"context":"ED0880FB0989BAD969B76D529C016D49","devicePixelRatio":4.5,"viewport":{"width":320,"height":658}}
index.js:912025-05-16T13:45:41.619Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[271 bytes]>, contexts: undefined }
index.js:912025-05-16T13:45:41.620Z INFO webdriver: BIDI RESULT {"id":8,"result":{"realm":"-219785209916946295.3726575127658728009","result":{"type":"undefined"},"type":"success"},"type":"success"}
index.js:912025-05-16T13:45:41.620Z INFO webdriver: BIDI RESULT {"id":9,"result":{"script":"45e3cc92-8342-41c4-b6c1-2c54322507c0"},"type":"success"}
index.js:912025-05-16T13:45:41.622Z INFO webdriver: BIDI RESULT {"id":10,"result":{},"type":"success"}
index.js:912025-05-16T13:45:41.622Z INFO webdriver: BIDI RESULT {"id":11,"result":{"script":"0608f338-c528-48a6-a041-c161f4e8a11e"},"type":"success"}
index.js:912025-05-16T13:45:41.624Z DEBUG @wdio/utils:shim: Finished to run "beforeTest" hook in 1ms
index.js:912025-05-16T13:45:41.624Z INFO webdriver: COMMAND navigateTo("file:///Users/nikolaoslytras/work/wdio_v9/test/specs/wp10469173-2000x2000-wallpapers.jpg")
index.js:912025-05-16T13:45:41.624Z INFO webdriver: [POST] http://localhost:59195/session/cf0e5e20ab09299d9b18d0e09615d642/url
index.js:912025-05-16T13:45:41.624Z INFO webdriver: DATA
Object {url: "file:///Users/nikolaoslytras/work/wdio_v9/test/specs/wp10469173-2000x2000-wallpapers.jpg"}
index.js:912025-05-16T13:45:41.644Z INFO webdriver: RESULT null
index.js:912025-05-16T13:45:41.644Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
index.js:912025-05-16T13:45:41.645Z INFO webdriver: BIDI RESULT {"id":12,"result":{"contexts":[{"children":[],"clientWindow":"1579773110","context":"ED0880FB0989BAD969B76D529C016D49","originalOpener":null,"parent":null,"url":"file:///Users/nikolaoslytras/work/wdio_v9/test/specs/wp10469173-2000x2000-wallpapers.jpg","userContext":"default"}]},"type":"success"}
index.js:912025-05-16T13:45:41.645Z INFO webdriver: BIDI COMMAND browsingContext.captureScreenshot {"context":"ED0880FB0989BAD969B76D529C016D49"}
index.js:912025-05-16T13:45:42.386Z ERROR webdriver: Failed parse message: Maximum call stack size exceededCode 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