Skip to content

Commit

Permalink
only allow opaque for responseType arg
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Oct 19, 2022
1 parent 562ad11 commit 44ed1ad
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import {
* - responseBody - optional, string for defining response body value, defaults to `emptyObj`. Possible values:
* - `emptyObj` - empty object
* - `emptyArr` - empty array
* - responseType - optional, string for defining response type, defaults to `default`.
* - responseType - optional, string for defining response type, defaults to `default`. Possible values:
* - opaque
*
* > Usage with no arguments will log fetch calls to browser console;
* which is useful for debugging but not permitted for production filter lists.
Expand Down Expand Up @@ -103,6 +104,11 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re
return;
}

let allowedResponseType;
if (responseType === 'default' || responseType === 'opaque') {
allowedResponseType = responseType;
}

const handlerWrapper = (target, thisArg, args) => {
let shouldPrevent = false;
const fetchData = getFetchData(args);
Expand Down Expand Up @@ -133,7 +139,7 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re

if (shouldPrevent) {
hit(source);
return noopPromiseResolve(strResponseBody, fetchData.url, responseType);
return noopPromiseResolve(strResponseBody, fetchData.url, allowedResponseType);
}

return Reflect.apply(target, thisArg, args);
Expand Down

0 comments on commit 44ed1ad

Please sign in to comment.