All files / scripts/instrumentor/patcher/xhr xhr.ts

71.42% Statements 5/7
80% Branches 4/5
100% Functions 1/1
71.42% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                    20x   20x         20x 20x   20x    
import { logger } from '../../../shared/logger'
import { PatcherContext } from '../context'
import { createPatchedOpen } from './open'
import { createPatchedSend } from './send'
 
/**
 * Patches the global XMLHttpRequest to automatically add Fingerprint signals
 * to requests made to protected APIs.
 */
export function patchXHR(ctx: PatcherContext) {
  const XHR = globalThis.XMLHttpRequest
 
  Iif (!XHR || typeof XHR.prototype?.open !== 'function' || typeof XHR.prototype?.send !== 'function') {
    logger.warn('XMLHttpRequest is not available.')
    return
  }
 
  XHR.prototype.open = createPatchedOpen(ctx)
  XHR.prototype.send = createPatchedSend(ctx)
 
  logger.debug('XMLHttpRequest patched successfully.')
}