Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(webdriver): guard Object.keys call on stringified request body#15221

Open
mnaoumov wants to merge 1 commit into
webdriverio:mainfrom
mnaoumov:fix/guard-object-keys-on-string-body
Open

fix(webdriver): guard Object.keys call on stringified request body#15221
mnaoumov wants to merge 1 commit into
webdriverio:mainfrom
mnaoumov:fix/guard-object-keys-on-string-body

Conversation

@mnaoumov
Copy link
Copy Markdown

Summary

  • Fixes [🐛 Bug]: browser.uploadFile() can crash with RangeError: Too many properties to enumerate on large request bodies #15213
  • In _request(), fullRequestOptions.body is already a JSON string at that point (stringified earlier in createOptions() via JSON.stringify(this.body)). Calling Object.keys() on a large string enumerates every character index as a property, causing V8 to throw RangeError: Too many properties to enumerate for large payloads (e.g., large screenshots or file uploads).
  • Added a typeof fullRequestOptions.body === 'object' guard before the Object.keys() call so it only runs on actual objects, not strings.

Root cause

// createOptions() does:
requestOptions.body = JSON.stringify(this.body)

// Later in _request():
if (fullRequestOptions.body && Object.keys(fullRequestOptions.body).length) {
    this.eventHandler.onLogData?.(fullRequestOptions.body)
}

Object.keys('...large string...') returns an array of character indices (['0', '1', '2', ...]). For strings with millions of characters, V8 cannot enumerate that many properties and throws RangeError: Too many properties to enumerate.

Fix

if (fullRequestOptions.body && typeof fullRequestOptions.body === 'object' && Object.keys(fullRequestOptions.body).length) {

This ensures Object.keys() is only called when body is an actual object (which shouldn't happen in practice given the current flow, but guards against the string case safely).

In `_request()`, `fullRequestOptions.body` is already a JSON string
(stringified in `createOptions()`). Calling `Object.keys()` on a large
string enumerates every character index, causing V8 to throw
`RangeError: Too many properties to enumerate` for large payloads.

Add a `typeof fullRequestOptions.body === 'object'` guard so
`Object.keys()` is only called on actual objects.

Fixes webdriverio#15213
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 29, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: mnaoumov / name: Michael Naumov (e157ead)

mnaoumov added a commit to mnaoumov/obsidian-integration-testing that referenced this pull request Apr 29, 2026
browser.pushFile() in [email protected] throws RangeError on large
payloads because FetchRequest._request() calls Object.keys() on a
JSON string body. Replace per-file pushFile calls with a single
tar.gz archive pushed via adb, which is both faster and sidesteps
the bug entirely.

The new flow: tar czf on host → adb push → tar xzf on device → cleanup.
Requires deviceId in AppiumTransportConfig (already available in options).

Upstream issue: webdriverio/webdriverio#15213
Upstream fix PR: webdriverio/webdriverio#15221

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: browser.uploadFile() can crash with RangeError: Too many properties to enumerate on large request bodies

1 participant