React Native SDK - patchNetwork method
This method patches XHR and Fetch apis to intercept network requests.
Signature
Section titled Signatureimport 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.
Parameters
Section titled Parameterscontext: 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
Options
Section titled OptionsignoreHeaders: Array<string> | boolean: headers to ignore, matched case-insensitively;truedrops 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 throughpatchNetwork:'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').
Have questions?
Section titled Have questions?If you have any questions about this process, feel free to reach out to us on our Slack .