Skip to content

Commit

Permalink
remove checking global methods in scriptlets
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Jan 12, 2023
1 parent ff07fb5 commit c19db5d
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 59 deletions.
6 changes: 0 additions & 6 deletions src/scriptlets/hide-in-shadow-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ import {
* ```
*/
export function hideInShadowDom(source, selector, baseSelector) {
// do nothing if browser does not support ShadowRoot
// https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot
if (!Element.prototype.attachShadow) {
return;
}

const hideElement = (targetElement) => {
const DISPLAY_NONE_CSS = 'display:none!important;';
targetElement.style.cssText = DISPLAY_NONE_CSS;
Expand Down
5 changes: 0 additions & 5 deletions src/scriptlets/prevent-element-src-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ import {
*/
/* eslint-enable max-len */
export function preventElementSrcLoading(source, tagName, match) {
// do nothing if browser does not support Proxy or Reflect
if (typeof Proxy === 'undefined' || typeof Reflect === 'undefined') {
return;
}

const srcMockData = {
// "KCk9Pnt9" = "()=>{}"
script: 'data:text/javascript;base64,KCk9Pnt9',
Expand Down
9 changes: 0 additions & 9 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ import {
*/
/* eslint-enable max-len */
export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', responseType = 'default') {
// do nothing if browser does not support fetch or Proxy (e.g. Internet Explorer)
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
if (typeof fetch === 'undefined'
|| typeof Proxy === 'undefined'
|| typeof Response === 'undefined') {
return;
}

let strResponseBody;
if (responseBody === '' || responseBody === 'emptyObj') {
strResponseBody = '{}';
Expand Down
6 changes: 0 additions & 6 deletions src/scriptlets/prevent-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ import {
*/
/* eslint-enable max-len */
export function preventXHR(source, propsToMatch, customResponseText) {
// do nothing if browser does not support Proxy (e.g. Internet Explorer)
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
if (typeof Proxy === 'undefined') {
return;
}

let response = '';
let responseText = '';
let responseUrl;
Expand Down
6 changes: 0 additions & 6 deletions src/scriptlets/remove-in-shadow-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ import {
* ```
*/
export function removeInShadowDom(source, selector, baseSelector) {
// do nothing if browser does not support ShadowRoot
// https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot
if (!Element.prototype.attachShadow) {
return;
}

const removeElement = (targetElement) => {
targetElement.remove();
};
Expand Down
9 changes: 0 additions & 9 deletions src/scriptlets/trusted-replace-fetch-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ import {
*/
/* eslint-enable max-len */
export function trustedReplaceFetchResponse(source, pattern = '', replacement = '', propsToMatch = '') {
// do nothing if browser does not support fetch or Proxy (e.g. Internet Explorer)
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
if (typeof fetch === 'undefined'
|| typeof Proxy === 'undefined'
|| typeof Response === 'undefined') {
return;
}

// Only allow pattern as empty string for logging purposes
if (pattern === '' && replacement !== '') {
logMessage(source, 'Pattern argument should not be empty string');
Expand Down
6 changes: 0 additions & 6 deletions src/scriptlets/trusted-replace-xhr-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ import {
*/
/* eslint-enable max-len */
export function trustedReplaceXhrResponse(source, pattern = '', replacement = '', propsToMatch = '') {
// do nothing if browser does not support Proxy (e.g. Internet Explorer)
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
if (typeof Proxy === 'undefined') {
return;
}

// Only allow pattern as empty string for logging purposes
if (pattern === '' && replacement !== '') {
const message = 'Pattern argument should not be empty string.';
Expand Down
11 changes: 0 additions & 11 deletions src/scriptlets/xml-prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ import {
/* eslint-enable max-len */

export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
// do nothing if browser does not support Reflect, fetch or Proxy (e.g. Internet Explorer)
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect
if (typeof Reflect === 'undefined'
|| typeof fetch === 'undefined'
|| typeof Proxy === 'undefined'
|| typeof Response === 'undefined') {
return;
}

let shouldPruneResponse = true;

if (!propsToRemove) {
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/match-stack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module(name);

test('Test matchStackTrace for working with getNativeRegexpTest helper', async (assert) => {
const notMatched = matchStackTrace('not_present', new Error().stack);
const matched = matchStackTrace('stack', new Error().stack);
const matched = matchStackTrace('qunit', new Error().stack);

assert.true(matched);
assert.false(notMatched);
Expand Down

0 comments on commit c19db5d

Please sign in to comment.