React Native SDK - patchNetwork method

Details about the patchNetwork method from OpenReplay's React Native SDK

React Native SDK ⁠-⁠ patchNetwork method

This method patches XHR and Fetch apis to intercept network requests.

import OR from '@openreplay/react-native'

OR.patchNetwork(
    global,
    (url) => url.includes('openreplaydomain'),
    { mode: 'fetch' }
)

Only the first call patches the network; later calls are ignored.

  • context: globalThis: current context of the app (to get fetch/xhr from). Default: global.
  • isServiceURL: (url: string) => boolean: function that checks if current request should be tracked (false) or skipped (true). Default: () => false (track everything).
  • options: Partial<Options>: options object
  • ignoreHeaders: Array<string> | boolean: headers to ignore, matched case-insensitively; true drops all headers (default: ['cookie', 'set-cookie', 'authorization'])
  • capturePayload: boolean: whether to capture request and response bodies (default: false)
  • sanitizer: (data: RequestResponseData) => RequestResponseData: function that sanitizes request/response before it is sent. A JSON response body is parsed into an object before it is passed in (default: undefined)
  • mode: 'fetch' | 'xhr' | 'all': which api to patch (default when called through patchNetwork: 'all')
interface RequestResponseData {
  readonly status: number;
  readonly method: string;
  url: string;
  request: { body: string | null; headers: Record<string, string> };
  response: { body: any; headers: Record<string, string> };
}

Note: React-Native fetch are using XHR under the hood (at the moment of writing), so using “all” (the default) can lead to duplicated requests in the recording. If you see duplicates, pass a single mode ('fetch' or 'xhr').

If you have any questions about this process, feel free to reach out to us on our Slack .