Skip to content

Commit

Permalink
improve log/matching forks for prevent-fetch, replace-fetch, replace-xhr
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 1, 2022
1 parent d2f0562 commit 8d7d5a3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re
// log if no propsToMatch given
const logMessage = `log: fetch( ${objectToString(fetchData)} )`;
hit(source, logMessage);
} else {
shouldPrevent = matchRequestProps(propsToMatch);
return Reflect.apply(target, thisArg, args);
}

shouldPrevent = matchRequestProps(propsToMatch);

if (shouldPrevent) {
hit(source);
return noopPromiseResolve(strResponseBody, fetchData.url, responseType);
Expand Down
5 changes: 3 additions & 2 deletions src/scriptlets/trusted-replace-fetch-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ export function trustedReplaceFetchResponse(source, pattern = '', replacement =
const logMessage = `log: fetch( ${objectToString(fetchData)} )`;
log(source, logMessage);
hit(source);
} else {
shouldReplace = matchRequestProps(propsToMatch, fetchData);
return Reflect.apply(target, thisArg, args);
}

shouldReplace = matchRequestProps(propsToMatch, fetchData);

if (!shouldReplace) {
return Reflect.apply(target, thisArg, args);
}
Expand Down
5 changes: 3 additions & 2 deletions src/scriptlets/trusted-replace-xhr-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ export function trustedReplaceXhrResponse(source, pattern = '', replacement = ''
// Log if no propsToMatch given
const logMessage = `log: xhr( ${objectToString(xhrData)} )`;
log(source, logMessage);
} else {
shouldReplace = matchRequestProps(propsToMatch, xhrData);
return Reflect.apply(target, thisArg, args);
}

shouldReplace = matchRequestProps(propsToMatch, xhrData);

// Trap setRequestHeader of target xhr object to mimic request headers later
if (shouldReplace) {
const setRequestHeaderWrapper = (target, thisArg, args) => {
Expand Down

0 comments on commit 8d7d5a3

Please sign in to comment.