Skip to content

Crash when capturing FormData: getFormDataEntries(body).reduce is not a function (entries() returns iterator) #170

@RikoRodriges

Description

@RikoRodriges

Describe the bug

We’re seeing a runtime crash when the inspector tries to serialize FormData request bodies.

The code currently does:

value: getFormDataEntries(body).reduce(...)

However, getFormDataEntries(body) may return the result of formData.entries(). In many environments (including React Native / polyfills), formData.entries() returns an iterator, not an array. Iterators don’t have .reduce(), which leads to a crash like:

TypeError: getFormDataEntries(body).reduce is not a function (it is undefined)

Where it happens

In getFormDataPostData, when request body is FormData and getFormDataEntries(body) returns an iterator.

Expected behavior

Serializing FormData should not crash. It should work regardless of whether entries are returned as an iterator or an array.

Suggested fix

Convert entries to an array before reducing (or iterate with for..of):

Option A (minimal diff):

const entries = getFormDataEntries(body);
const entriesArray = Array.isArray(entries) ? entries : Array.from(entries || []);
return {
  type: "form-data",
  value: entriesArray.reduce((acc, [key, value]) => {
    // existing logic
    return acc;
  }, {})
};

Option B (most compatible):
Use for...of over getFormDataEntries(body) and build the object without reduce.

Notes
getFormDataEntries currently may return:

  • formData.entries() (iterator)
  • formData._parts (array in some RN implementations)
  • []

The crash occurs specifically when the iterator path is used.

System Info

System:
  OS: macOS 15.5
  CPU: (10) arm64 Apple M1 Pro
  Memory: 135.34 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.6.0
    path: /Users/test/.nvm/versions/node/v24.6.0/bin/node
  Yarn: Not Found
  npm:
    version: 11.5.1
    path: /Users/test/.nvm/versions/node/v24.6.0/bin/npm
  Watchman:
    version: 2025.06.23.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.13.0
    path: /Users/test/.rvm/gems/ruby-2.7.4/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.5
      - iOS 18.5
      - macOS 15.5
      - tvOS 18.5
      - visionOS 2.5
      - watchOS 11.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2512.13991807
  Xcode:
    version: 16.4/16F6
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.7.4
    path: /Users/test/.rvm/rubies/ruby-2.7.4/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.2
    wanted: "catalog:"
  react:
    installed: 19.1.0
    wanted: "catalog:"
  react-native:
    installed: 0.81.5
    wanted: "catalog:"
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Rozenite Version

1.2.0

Reproduction

Steps to reproduce

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions