createInjection function

String createInjection(
  1. String urlRegex,
  2. String bodySniffRegex,
  3. bool bodySniffEnabled,
  4. RequestMethodType method,
  5. bool disableRequestReplay,
  6. InjectionType injectionType,
)

Implementation

String createInjection(
  String urlRegex,
  String bodySniffRegex,
  bool bodySniffEnabled,
  RequestMethodType method,
  bool disableRequestReplay,
  InjectionType injectionType,
) {
  final s = """
    window.ReclaimInjected = true;
    ${injectionType == InjectionType.NONE ? NONE : ''}
    ${injectionType == InjectionType.XHOOK ? XHOOK : ''}
    ${injectionType == InjectionType.MSWJS ? MSWJS : ''}
        window.flutter_inappwebview.callHandler('requestLogs' ,JSON.stringify({ requestBody: requestBody,url: url, responseBody : responseText,method : requestMethod}));
        if(url.match('$urlRegex') && requestMethod === '${method.name}' && (!$bodySniffEnabled || ($bodySniffEnabled && requestBody.match('$bodySniffRegex')))){
          window.flutter_inappwebview.callHandler('proofData', JSON.stringify({requestBody: requestBody,url: url,headers: headers ,response : responseText}));
        }
      }
      catch (e){
        window.flutter_inappwebview.callHandler('errorLogs', JSON.stringify({log:e.message }));
      }
    });
    ${!disableRequestReplay ? requestReplayInjection : """
    if(!window.reclaimFetchInjected){
      window.addEventListener('load', function(event) {
        window.flutter_inappwebview.callHandler('requestLogs' ,JSON.stringify({ requestBody: '',url: window.location.href, responseBody :  document.documentElement.outerHTML,method : "GET"}));
        if(window.location.href.match('$urlRegex') && 'GET' === '$method'){
          window.flutter_inappwebview.callHandler('proofData', JSON.stringify({requestBody: '',url: window.location.href,headers: {} ,response : document.documentElement.outerHTML}));
        }
      });
      window.reclaimFetchInjected = true;
    }
    """}
  true;
  """;
  return s;
}