Skip to content

Commit

Permalink
add comments for getHeaderWrapper() and getAllHeadersWrapper()
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed May 16, 2023
1 parent 8ff8421 commit 10c0393
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/scriptlets/prevent-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ export function preventXHR(source, propsToMatch, customResponseText) {
return undefined;
};

/**
* Mock XMLHttpRequest.prototype.getHeaderHandler() to avoid adblocker detection.
*
* @param {Function} target XMLHttpRequest.prototype.getHeaderHandler().
* @param {XMLHttpRequest} thisArg The request.
* @param {string[]} args Header name is passed as first argument.
*
* @returns {string|null} Header value or null if header is not set.
*/
const getHeaderWrapper = (target, thisArg, args) => {
if (!thisArg.collectedHeaders.length) {
return null;
Expand All @@ -238,6 +247,14 @@ export function preventXHR(source, propsToMatch, customResponseText) {
: null;
};

/**
* Mock XMLHttpRequest.prototype.getAllResponseHeaders() to avoid adblocker detection.
*
* @param {Function} target XMLHttpRequest.prototype.getAllResponseHeaders().
* @param {XMLHttpRequest} thisArg The request.
*
* @returns {string} All headers as a string. For no headers an empty string is returned.
*/
const getAllHeadersWrapper = (target, thisArg) => {
if (!thisArg.collectedHeaders.length) {
return '';
Expand Down

0 comments on commit 10c0393

Please sign in to comment.