|
1 | 1 |
|
2 | 2 | /** |
3 | 3 | * AdGuard Scriptlets |
4 | | - * Version 1.9.72 |
| 4 | + * Version 1.9.83 |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | (function () { |
|
1872 | 1872 | * @param args fetch args |
1873 | 1873 | * @returns data object |
1874 | 1874 | */ |
1875 | | - var getFetchData = function getFetchData(args) { |
| 1875 | + var getFetchData = function getFetchData(args, nativeRequestClone) { |
1876 | 1876 | var fetchPropsObj = {}; |
| 1877 | + var resource = args[0]; |
1877 | 1878 | var fetchUrl; |
1878 | 1879 | var fetchInit; |
1879 | | - if (args[0] instanceof Request) { |
| 1880 | + if (resource instanceof Request) { |
| 1881 | + // Get real properties in case if data URL was used |
| 1882 | + // and properties were set by Object.defineProperty |
| 1883 | + // https://github.com/AdguardTeam/Scriptlets/issues/367 |
| 1884 | + var realData = nativeRequestClone.call(resource); |
1880 | 1885 | // if Request passed to fetch, it will be in array |
1881 | | - var requestData = getRequestData(args[0]); |
| 1886 | + var requestData = getRequestData(realData); |
1882 | 1887 | fetchUrl = requestData.url; |
1883 | 1888 | fetchInit = requestData; |
1884 | 1889 | } else { |
1885 | | - fetchUrl = args[0]; // eslint-disable-line prefer-destructuring |
| 1890 | + fetchUrl = resource; // eslint-disable-line prefer-destructuring |
1886 | 1891 | fetchInit = args[1]; // eslint-disable-line prefer-destructuring |
1887 | 1892 | } |
1888 | 1893 |
|
|
3937 | 3942 | if (prevSetter !== undefined) { |
3938 | 3943 | prevSetter(a); |
3939 | 3944 | } |
| 3945 | + // Set a proxy trap to observe changes |
| 3946 | + // This is a partial fix and only works with a single scriptlet, |
| 3947 | + // a full fix requires synchronisation between the scriptlets |
| 3948 | + // TODO: add proper fix when synchronisation between scriptlets is added |
| 3949 | + // https://github.com/AdguardTeam/Scriptlets/issues/330 |
| 3950 | + if (a instanceof Object) { |
| 3951 | + // Get properties which should be checked and remove first one |
| 3952 | + // because it's current object |
| 3953 | + var propertiesToCheck = property.split('.').slice(1); |
| 3954 | + a = new Proxy(a, { |
| 3955 | + get: function get(target, propertyKey, val) { |
| 3956 | + // Check if object contains required property, if so |
| 3957 | + // check if current value is equal to constantValue, if not, set it to constantValue |
| 3958 | + propertiesToCheck.reduce(function (object, currentProp, index, array) { |
| 3959 | + var currentObj = object === null || object === void 0 ? void 0 : object[currentProp]; |
| 3960 | + if (currentObj && index === array.length - 1 && currentObj !== constantValue) { |
| 3961 | + object[currentProp] = constantValue; |
| 3962 | + } |
| 3963 | + return currentObj || object; |
| 3964 | + }, target); |
| 3965 | + return Reflect.get(target, propertyKey, val); |
| 3966 | + } |
| 3967 | + }); |
| 3968 | + } |
3940 | 3969 | handler.set(a); |
3941 | 3970 | } |
3942 | 3971 | }); |
|
4470 | 4499 | * A simple scriptlet which only purpose is to print arguments to console. |
4471 | 4500 | * This scriptlet can be helpful for debugging and troubleshooting other scriptlets. |
4472 | 4501 | * |
| 4502 | + * Related ABP source: |
| 4503 | + * https://gitlab.com/eyeo/snippets/-/blob/main/source/introspection/log.js |
| 4504 | + * |
4473 | 4505 | * ### Examples |
4474 | 4506 | * |
4475 | 4507 | * ```adblock |
|
4485 | 4517 | console.log(args); // eslint-disable-line no-console |
4486 | 4518 | } |
4487 | 4519 |
|
4488 | | - log$1.names = ['log']; |
| 4520 | + log$1.names = ['log', 'abp-log']; |
4489 | 4521 |
|
4490 | 4522 | /* eslint-disable no-eval, no-extra-bind */ |
4491 | 4523 |
|
|
5609 | 5641 | } |
5610 | 5642 | adjustSetInterval$1.names = ['adjust-setInterval', |
5611 | 5643 | // aliases are needed for matching the related scriptlet converted into our syntax |
5612 | | - 'nano-setInterval-booster.js', 'ubo-nano-setInterval-booster.js', 'nano-sib.js', 'ubo-nano-sib.js', 'ubo-nano-setInterval-booster', 'ubo-nano-sib']; |
| 5644 | + 'nano-setInterval-booster.js', 'ubo-nano-setInterval-booster.js', 'nano-sib.js', 'ubo-nano-sib.js', 'adjust-setInterval.js', 'ubo-adjust-setInterval.js', 'ubo-nano-setInterval-booster', 'ubo-nano-sib', 'ubo-adjust-setInterval']; |
5613 | 5645 | adjustSetInterval$1.injections = [hit, isValidCallback, toRegExp, getBoostMultiplier, isDelayMatched, logMessage, |
5614 | 5646 | // following helpers should be injected as helpers above use them |
5615 | 5647 | nativeIsNaN, nativeIsFinite, getMatchDelay, shouldMatchAnyDelay]; |
|
5705 | 5737 | } |
5706 | 5738 | adjustSetTimeout$1.names = ['adjust-setTimeout', |
5707 | 5739 | // aliases are needed for matching the related scriptlet converted into our syntax |
5708 | | - 'nano-setTimeout-booster.js', 'ubo-nano-setTimeout-booster.js', 'nano-stb.js', 'ubo-nano-stb.js', 'ubo-nano-setTimeout-booster', 'ubo-nano-stb']; |
| 5740 | + 'adjust-setTimeout.js', 'ubo-adjust-setTimeout.js', 'nano-setTimeout-booster.js', 'ubo-nano-setTimeout-booster.js', 'nano-stb.js', 'ubo-nano-stb.js', 'ubo-adjust-setTimeout', 'ubo-nano-setTimeout-booster', 'ubo-nano-stb']; |
5709 | 5741 | adjustSetTimeout$1.injections = [hit, isValidCallback, toRegExp, getBoostMultiplier, isDelayMatched, logMessage, |
5710 | 5742 | // following helpers should be injected as helpers above use them |
5711 | 5743 | nativeIsNaN, nativeIsFinite, getMatchDelay, shouldMatchAnyDelay]; |
|
6398 | 6430 | if (typeof fetch === 'undefined' || typeof Proxy === 'undefined' || typeof Response === 'undefined') { |
6399 | 6431 | return; |
6400 | 6432 | } |
| 6433 | + var nativeRequestClone = Request.prototype.clone; |
6401 | 6434 | var strResponseBody; |
6402 | 6435 | if (responseBody === '' || responseBody === 'emptyObj') { |
6403 | 6436 | strResponseBody = '{}'; |
|
6420 | 6453 | } |
6421 | 6454 | var handlerWrapper = async function handlerWrapper(target, thisArg, args) { |
6422 | 6455 | var shouldPrevent = false; |
6423 | | - var fetchData = getFetchData(args); |
| 6456 | + var fetchData = getFetchData(args, nativeRequestClone); |
6424 | 6457 | if (typeof propsToMatch === 'undefined') { |
6425 | 6458 | logMessage(source, "fetch( ".concat(objectToString(fetchData), " )"), true); |
6426 | 6459 | hit(source); |
|
7221 | 7254 | } |
7222 | 7255 | } |
7223 | 7256 | } |
7224 | | - forceWindowClose$1.names = ['close-window', 'window-close-if.js', 'ubo-window-close-if.js', 'ubo-window-close-if']; |
| 7257 | + forceWindowClose$1.names = ['close-window', |
| 7258 | + // aliases are needed for matching the related scriptlet converted into our syntax |
| 7259 | + 'window-close-if.js', 'ubo-window-close-if.js', 'ubo-window-close-if', 'close-window.js', 'ubo-close-window.js', 'ubo-close-window']; |
7225 | 7260 | forceWindowClose$1.injections = [hit, toRegExp, logMessage]; |
7226 | 7261 |
|
7227 | 7262 | /* eslint-disable max-len */ |
|
7338 | 7373 | // Aliases are needed for matching the related scriptlet converted into our syntax |
7339 | 7374 | // These are used by UBO rules syntax |
7340 | 7375 | // https://github.com/gorhill/uBlock/wiki/Resources-Library#general-purpose-scriptlets |
7341 | | - 'refresh-defuser.js', 'refresh-defuser', |
| 7376 | + 'prevent-refresh.js', 'refresh-defuser.js', 'refresh-defuser', |
7342 | 7377 | // Prefix 'ubo-' is required to run converted rules |
7343 | | - 'ubo-refresh-defuser.js', 'ubo-refresh-defuser']; |
| 7378 | + 'ubo-prevent-refresh.js', 'ubo-prevent-refresh', 'ubo-refresh-defuser.js', 'ubo-refresh-defuser']; |
7344 | 7379 | preventRefresh$1.injections = [hit, getNumberFromString, logMessage, nativeIsNaN]; |
7345 | 7380 |
|
7346 | 7381 | /* eslint-disable max-len, consistent-return */ |
|
7675 | 7710 | } |
7676 | 7711 | if (matchRequestProps(source, propsToMatch, xhrData)) { |
7677 | 7712 | thisArg.shouldBePrevented = true; |
| 7713 | + thisArg.headersReceived = !!thisArg.headersReceived; |
7678 | 7714 | } |
7679 | 7715 |
|
7680 | 7716 | // Trap setRequestHeader of target xhr object to mimic request headers later |
7681 | | - if (thisArg.shouldBePrevented) { |
| 7717 | + if (thisArg.shouldBePrevented && !thisArg.headersReceived) { |
| 7718 | + thisArg.headersReceived = true; |
7682 | 7719 | thisArg.collectedHeaders = []; |
7683 | 7720 | var setRequestHeaderWrapper = function setRequestHeaderWrapper(target, thisArg, args) { |
7684 | 7721 | // Collect headers |
|
8432 | 8469 | */ |
8433 | 8470 | // TODO: make it compatible with $hls modifier |
8434 | 8471 | var pruneM3U = function pruneM3U(text) { |
8435 | | - var lines = text.split(/\n\r|\n|\r/); |
| 8472 | + var lines = text.split(/\r?\n/); |
8436 | 8473 | if (text.includes(COMCAST_AD_MARKER.VMAP_AD_BREAK)) { |
8437 | 8474 | lines = pruneVmapBlock(lines); |
8438 | 8475 | return lines.filter(function (l) { |
|
8965 | 9002 | return; |
8966 | 9003 | } |
8967 | 9004 | var shouldLog = pattern === '' && replacement === ''; |
| 9005 | + var nativeRequestClone = Request.prototype.clone; |
8968 | 9006 | var nativeFetch = fetch; |
8969 | 9007 | var shouldReplace = false; |
8970 | 9008 | var fetchData; |
8971 | 9009 | var handlerWrapper = function handlerWrapper(target, thisArg, args) { |
8972 | | - fetchData = getFetchData(args); |
| 9010 | + fetchData = getFetchData(args, nativeRequestClone); |
8973 | 9011 | if (shouldLog) { |
8974 | 9012 | // log if no propsToMatch given |
8975 | 9013 | logMessage(source, "fetch( ".concat(objectToString(fetchData), " )"), true); |
|
20210 | 20248 | return isM3U(text) && regexp.test(text); |
20211 | 20249 | }; |
20212 | 20250 | var pruneM3U = function pruneM3U(text) { |
20213 | | - var lines = text.split(/\n\r|\n|\r/); |
| 20251 | + var lines = text.split(/\r?\n/); |
20214 | 20252 | if (text.includes(COMCAST_AD_MARKER.VMAP_AD_BREAK)) { |
20215 | 20253 | lines = pruneVmapBlock(lines); |
20216 | 20254 | return lines.filter(function (l) { |
|
21520 | 21558 | if (typeof fetch === "undefined" || typeof Proxy === "undefined" || typeof Response === "undefined") { |
21521 | 21559 | return; |
21522 | 21560 | } |
| 21561 | + var nativeRequestClone = Request.prototype.clone; |
21523 | 21562 | var strResponseBody; |
21524 | 21563 | if (responseBody === "" || responseBody === "emptyObj") { |
21525 | 21564 | strResponseBody = "{}"; |
|
21540 | 21579 | } |
21541 | 21580 | var handlerWrapper = async function handlerWrapper(target, thisArg, args) { |
21542 | 21581 | var shouldPrevent = false; |
21543 | | - var fetchData = getFetchData(args); |
| 21582 | + var fetchData = getFetchData(args, nativeRequestClone); |
21544 | 21583 | if (typeof propsToMatch === "undefined") { |
21545 | 21584 | logMessage(source, "fetch( ".concat(objectToString(fetchData), " )"), true); |
21546 | 21585 | hit(source); |
@@ -21599,16 +21638,18 @@ |
21599 | 21638 | window.__debug(source); |
21600 | 21639 | } |
21601 | 21640 | } |
21602 | | - function getFetchData(args) { |
| 21641 | + function getFetchData(args, nativeRequestClone) { |
21603 | 21642 | var fetchPropsObj = {}; |
| 21643 | + var resource = args[0]; |
21604 | 21644 | var fetchUrl; |
21605 | 21645 | var fetchInit; |
21606 | | - if (args[0] instanceof Request) { |
21607 | | - var requestData = getRequestData(args[0]); |
| 21646 | + if (resource instanceof Request) { |
| 21647 | + var realData = nativeRequestClone.call(resource); |
| 21648 | + var requestData = getRequestData(realData); |
21608 | 21649 | fetchUrl = requestData.url; |
21609 | 21650 | fetchInit = requestData; |
21610 | 21651 | } else { |
21611 | | - fetchUrl = args[0]; |
| 21652 | + fetchUrl = resource; |
21612 | 21653 | fetchInit = args[1]; |
21613 | 21654 | } |
21614 | 21655 | fetchPropsObj.url = fetchUrl; |
|
24373 | 24414 | if (prevSetter !== undefined) { |
24374 | 24415 | prevSetter(a); |
24375 | 24416 | } |
| 24417 | + if (a instanceof Object) { |
| 24418 | + var propertiesToCheck = property.split(".").slice(1); |
| 24419 | + a = new Proxy(a, { |
| 24420 | + get: function get(target, propertyKey, val) { |
| 24421 | + propertiesToCheck.reduce(function (object, currentProp, index, array) { |
| 24422 | + var currentObj = object === null || object === void 0 ? void 0 : object[currentProp]; |
| 24423 | + if (currentObj && index === array.length - 1 && currentObj !== constantValue) { |
| 24424 | + object[currentProp] = constantValue; |
| 24425 | + } |
| 24426 | + return currentObj || object; |
| 24427 | + }, target); |
| 24428 | + return Reflect.get(target, propertyKey, val); |
| 24429 | + } |
| 24430 | + }); |
| 24431 | + } |
24376 | 24432 | handler.set(a); |
24377 | 24433 | } |
24378 | 24434 | }); |
@@ -25599,11 +25655,12 @@ |
25599 | 25655 | return; |
25600 | 25656 | } |
25601 | 25657 | var shouldLog = pattern === "" && replacement === ""; |
| 25658 | + var nativeRequestClone = Request.prototype.clone; |
25602 | 25659 | var nativeFetch = fetch; |
25603 | 25660 | var shouldReplace = false; |
25604 | 25661 | var fetchData; |
25605 | 25662 | var handlerWrapper = function handlerWrapper(target, thisArg, args) { |
25606 | | - fetchData = getFetchData(args); |
| 25663 | + fetchData = getFetchData(args, nativeRequestClone); |
25607 | 25664 | if (shouldLog) { |
25608 | 25665 | logMessage(source, "fetch( ".concat(objectToString(fetchData), " )"), true); |
25609 | 25666 | hit(source); |
@@ -25713,16 +25770,18 @@ |
25713 | 25770 | } |
25714 | 25771 | nativeConsole("".concat(name, ": ").concat(message)); |
25715 | 25772 | } |
25716 | | - function getFetchData(args) { |
| 25773 | + function getFetchData(args, nativeRequestClone) { |
25717 | 25774 | var fetchPropsObj = {}; |
| 25775 | + var resource = args[0]; |
25718 | 25776 | var fetchUrl; |
25719 | 25777 | var fetchInit; |
25720 | | - if (args[0] instanceof Request) { |
25721 | | - var requestData = getRequestData(args[0]); |
| 25778 | + if (resource instanceof Request) { |
| 25779 | + var realData = nativeRequestClone.call(resource); |
| 25780 | + var requestData = getRequestData(realData); |
25722 | 25781 | fetchUrl = requestData.url; |
25723 | 25782 | fetchInit = requestData; |
25724 | 25783 | } else { |
25725 | | - fetchUrl = args[0]; |
| 25784 | + fetchUrl = resource; |
25726 | 25785 | fetchInit = args[1]; |
25727 | 25786 | } |
25728 | 25787 | fetchPropsObj.url = fetchUrl; |
|
26085 | 26144 | } |
26086 | 26145 | if (matchRequestProps(source, propsToMatch, xhrData)) { |
26087 | 26146 | thisArg.shouldBePrevented = true; |
| 26147 | + thisArg.headersReceived = !!thisArg.headersReceived; |
26088 | 26148 | } |
26089 | | - if (thisArg.shouldBePrevented) { |
| 26149 | + if (thisArg.shouldBePrevented && !thisArg.headersReceived) { |
| 26150 | + thisArg.headersReceived = true; |
26090 | 26151 | thisArg.collectedHeaders = []; |
26091 | 26152 | var setRequestHeaderWrapper = function setRequestHeaderWrapper(target, thisArg, args) { |
26092 | 26153 | thisArg.collectedHeaders.push(args); |
@@ -27579,13 +27640,19 @@ |
27579 | 27640 | "ubo-nano-setInterval-booster.js": adjustSetInterval, |
27580 | 27641 | "nano-sib.js": adjustSetInterval, |
27581 | 27642 | "ubo-nano-sib.js": adjustSetInterval, |
| 27643 | + "adjust-setInterval.js": adjustSetInterval, |
| 27644 | + "ubo-adjust-setInterval.js": adjustSetInterval, |
27582 | 27645 | "ubo-nano-setInterval-booster": adjustSetInterval, |
27583 | 27646 | "ubo-nano-sib": adjustSetInterval, |
| 27647 | + "ubo-adjust-setInterval": adjustSetInterval, |
27584 | 27648 | "adjust-setTimeout": adjustSetTimeout, |
| 27649 | + "adjust-setTimeout.js": adjustSetTimeout, |
| 27650 | + "ubo-adjust-setTimeout.js": adjustSetTimeout, |
27585 | 27651 | "nano-setTimeout-booster.js": adjustSetTimeout, |
27586 | 27652 | "ubo-nano-setTimeout-booster.js": adjustSetTimeout, |
27587 | 27653 | "nano-stb.js": adjustSetTimeout, |
27588 | 27654 | "ubo-nano-stb.js": adjustSetTimeout, |
| 27655 | + "ubo-adjust-setTimeout": adjustSetTimeout, |
27589 | 27656 | "ubo-nano-setTimeout-booster": adjustSetTimeout, |
27590 | 27657 | "ubo-nano-stb": adjustSetTimeout, |
27591 | 27658 | "debug-current-inline-script": debugCurrentInlineScript, |
|
27604 | 27671 | "window-close-if.js": forceWindowClose, |
27605 | 27672 | "ubo-window-close-if.js": forceWindowClose, |
27606 | 27673 | "ubo-window-close-if": forceWindowClose, |
| 27674 | + "close-window.js": forceWindowClose, |
| 27675 | + "ubo-close-window.js": forceWindowClose, |
| 27676 | + "ubo-close-window": forceWindowClose, |
27607 | 27677 | "hide-in-shadow-dom": hideInShadowDom, |
27608 | 27678 | "inject-css-in-shadow-dom": injectCssInShadowDom, |
27609 | 27679 | "json-prune": jsonPrune, |
|
27612 | 27682 | "ubo-json-prune": jsonPrune, |
27613 | 27683 | "abp-json-prune": jsonPrune, |
27614 | 27684 | log: log, |
| 27685 | + "abp-log": log, |
27615 | 27686 | "log-addEventListener": logAddEventListener, |
27616 | 27687 | "addEventListener-logger.js": logAddEventListener, |
27617 | 27688 | "ubo-addEventListener-logger.js": logAddEventListener, |
|
27670 | 27741 | "ubo-popads.net.js": preventPopadsNet, |
27671 | 27742 | "ubo-popads.net": preventPopadsNet, |
27672 | 27743 | "prevent-refresh": preventRefresh, |
| 27744 | + "prevent-refresh.js": preventRefresh, |
27673 | 27745 | "refresh-defuser.js": preventRefresh, |
27674 | 27746 | "refresh-defuser": preventRefresh, |
| 27747 | + "ubo-prevent-refresh.js": preventRefresh, |
| 27748 | + "ubo-prevent-refresh": preventRefresh, |
27675 | 27749 | "ubo-refresh-defuser.js": preventRefresh, |
27676 | 27750 | "ubo-refresh-defuser": preventRefresh, |
27677 | 27751 | "prevent-requestAnimationFrame": preventRequestAnimationFrame, |
|
0 commit comments