Resources Library·续1
Also see:
- AdGuard abort-on-stack-trace
addEventListener-defuser.js ↪
aeld.js /
prevent-addEventListener.js
Prevents attaching event listeners.
Parameters (when using positional arguments): - optional, string/regular expression, name of the event listener to defuse - optional, string/regular expression matching in stringified handler function, narrows down defusing to specific handler
Examples:
- vev.io##+js(aeld, adb.updated)
- newser.com##+js(aeld, load, Object)
- vivo.sx##+js(aeld, , preventDefault)
- vidto.me##+js(aeld, /^(?:click|mousedown|mousemove|touchstart|touchend|touchmove)$/, system.popunder)
Tokens:
- "runAt": when this parameter is present, uBO will take it into account to possibly defer defusing the event listener <sup>(New in 1.49.3b4)</sup>:
- end: execute scriptlet at DOMContentLoaded event ("interactive")
- idle: execute scriptlet at load event ("complete")
- "elements": if present, will be used to apply the scriptlet to only elements matching the selector <sup>(New in 1.55.1b1)</sup>
- must be a valid CSS selector (also window and document elements can be used as a selector <sup>(New in 1.58.1b5)</sup>)
- "debug": an integer value telling when to break into the debugger, useful to inspect the debugger's call stack.
- 1: break into the debugger when both type and pattern match, so effectively when defusing is taking place.
- 2: break into the debugger when either type or pattern matches.
<details> <summary> ● "log": (deprecated)</summary>
▬▬► SPOILER START ◄▬▬
- "log": an integer value telling when to log (see uBlockOrigin/uAssets#17907):
- 1: log only when both type and pattern matches, i.e. when a call to
addEventListener()is defused - 2: log when either the type or pattern matches
- 3: log all calls to
addEventListener()
- 1: log only when both type and pattern matches, i.e. when a call to
Examples:
- wikipedia.org##+js(aeld, /mouse/, /.^/, log, 2)
- wikipedia.org##+js(aeld, , /.^/, log, 2)
- wikipedia.org##+js(aeld, , , log, 1)
- wikipedia.org##+js(aeld, _, , log, 3)
The first filter will log calls to addEventListener() which have the pattern "mouse" in the event type (so "mouseover", "mouseout", etc.) without defusing any of them (because pattern can't match anything).
The second filter will log all calls without defusing any of them (because type can't match anything).
The third filter will log and defuse all calls to addEventListener()
The fourth filter will log all calls to addEventListener() without defusing any of them
▬▬► SPOILER END ◄▬▬
</details>
(read about the new method of logging scriptlets)
Examples:
jpvhub.com##+js(aeld, click, popMagic, runAt, idle)subkade.ir##+js(aeld, click, return"undefined", elements, a.indirect)wikipedia.org##+js(aeld)
The third filter will log all calls to addEventListener() without defusing any of them
Also see:
- AdGuard prevent-addEventListener
~aell.js~ /
~addEventListener-logger.js~ ↪
Removed in 1.48.1b3.
Logs to the console event listeners created on page.
The logging or debugging of addEventListener() calls can now be done with the addEventListenerDefuser scriptlet, which now supports named arguments.
Also see:
- AdGuard log-addEventListener
remove-cookie.js ↪
cookie-remover.js
Removes current page cookies specified by name. For current domain, wildcard (dot) subdomain(s), after 1.28.0 also for domain one level above www, current and / path, script accessible (HttpOnly=false), on load and before unload.
Caveats: cookies set for higher level domain will not be removed. For example, if current page domain is page.example.com, cookies set for example.com will not be removed. One exception is www subdomain, which will work after 1.28.0.
Parameters: - optional, string/regular expression, matching in the name of the cookie
Tokens:
- "when": when this parameter is present, it adds ability to trigger cookie removal on specific events (with delay 500ms):
- when "when" is not present: executes on page load and before unload
- scroll: executes when scrolling page (since 1.53.5rc3)
- keydown: executes when key pressed (since 1.53.5rc4)
Examples:
- subdivx.com##+js(cookie-remover, ref_cookie)
- discovermagazine.com##+js(remove-cookie, AWSALBTG, when, scroll)
(solves: 'remove-cookie' scriptlet sometimes does not work)
Also see:
- AdGuard remove-cookie
~csp.js~ ↪
Removed. Deprecated by $csp network filter option.
Applies content security policy by inserting <meta http-equiv=Content-Security-Policy content="*directive*"> tag to html <head> element.
Read more at https://www.w3.org/TR/CSP2/#delivery-html-meta-element
Content Security Policy Quick Reference Guide
Parameters: - required, valid Content Security Policy directive
call-nothrow.js ↪
New in 1.48.1b0.
Prevents a call to an existing function from throwing an exception. It encloses existing functions in this block and ignores the exception:
try {
[existing function]
}
catch() {
[ignore when throws]
}
It will return undefined because returning variable is never set.
The exception will be caught by the scriptlet and neutralized. The first argument must be a reference to a function call. At the moment, the function call must exist at the time the scriptlet is called.
Parameters: - required, a reference to a function call
Examples:
- example.com##+js(call-nothrow, Object.defineProperty)
Also see:
- AdGuard call-nothrow
disable-newtab-links.js ↪
Prevents creating new tabs/windows by deactivating links with target attribute.
Parameters: - none
Examples:
- there.to##+js(disable-newtab-links)
To prevent new tabs/windows by specifying the location URL, see: window-close-if.js
Also see:
- AdGuard disable-newtab-links
evaldata-prune.js ↪
New in 1.49.3rc15
Intercepts calls to eval() and will work only if what is passed to eval can be parsed as JSON.
For parameters, see: json-prune
When no "prune paths" argument (first parameter) is provided, the scriptlet is used for logging purpose and the "needle paths" argument (second parameter) is used to filter logging output.
Examples:
- m.nivod4.tv##+js(evaldata-prune, entity.commercial)
Also see:
- AdGuard evaldata-prune
trusted-prune-inbound-object.js ↪
Trusted scriptlet
New in 1.52.3rc0
To perform object pruning for any given call which has an object as argument (hence "inbound").
Parameters:
- required, the name of the property to trap. Must be a function, and must exist when the scriptlet tries to install the trap.
- required, the position of the object to prune in the argument list when the trapped function is called. The position is 1-based and must be an integer greater than 0.
- required, the properties to prune (as with
json-prune) - optional, the properties which must all be present for pruning to occur
(as with
json-prune)
Varargs:
- dontOverwrite, 1: do not modify the target inbound object.
- stackToMatch: string or regular expression that must match the current function call stack trace. Prepend pattern with ! to test for unmatched patterns in stack trace.
Examples:
- Remove
titleandnameproperties before passing the object toJSON.stringifycall:
example.org##+js(trusted-prune-inbound-object, JSON.stringify, 1, title name)
```
2. Remove `status` property before passing the object to `Object.keys`
call but do not modify caller's instance of the object:
```adblock
example.org##+js(trusted-prune-inbound-object, Object.keys, 1, status, , dontOverwrite, 1)
```
Also see:
- [AdGuard `trusted-prune-inbound-object`](https://github.com/AdguardTeam/Scriptlets/blob/master/wiki/about-trusted-scriptlets.md#trusted-prune-inbound-object)
***
### trusted-prune-outbound-object.js [↪](https://github.com/gorhill/uBlock/blob/66e3a1ad47162a89709e99072e5eaecdd83cb633/assets/resources/scriptlets.js#L4713)
#### _Trusted scriptlet_
New in [1.52.3rc3](https://github.com/gorhill/uBlock/commit/86f0d6dd978b79a34ffa257825539fb4446759a4)
Essentially a complement of [`trusted-prune-inbound-object`](#trusted-prune-inbound-objectjs-) added in [1.52.3rc0](https://github.com/gorhill/uBlock/commit/1c9da227d714250c0b6319e2f635998f9869a70d)
To perform object pruning on any object returned synchronously by
any given call.
Parameters:
- required, the name of the property to trap. Must be a function, and must
exist when the scriptlet tries to install the trap.
- required, the properties to prune (as with [`json-prune`](#json-prunejs-))
- optional, the properties which must all be present for pruning to occur
(as with [`json-prune`](#json-prunejs-))
The scriptlets `json-prune` and `evaldata-prune` essentially
perform the same function, and will eventually be rewritten to
internally delegate to generic `trusted-prune-outbound-object`.
***
### json-prune.js [↪](https://github.com/gorhill/uBlock/blob/d338e4c4b6caf339873a60c9d48fde58e9a495ce/assets/resources/scriptlets.js#L365)
New in [1.23.0](https://github.com/gorhill/uBlock/commit/2fd86a66fcc2665e5672cc5862e24b3782ee7504)
Intercepts calls to `JSON.parse()` and `Response.json()`<sup>[New in 1.31.0](https://github.com/gorhill/uBlock/commit/13f92756befaa9a8d3ba1615bd7abc7075758c67)</sup>. If the result of the parsing is an Object, remove specified properties from the result before returning to the caller.
Parameters:
- optional, string, a list of space-separated properties to remove
- optional,
- string, a list of space-separated properties which must be all present for the pruning to occur; OR
- string/_regular expression_, for logging purposes, matching in stringified JSON payloads (New in [1.27.0](https://github.com/gorhill/uBlock/commit/578594bbd7c545b62f18267d640a605f8e07a53a))
- optional, string or regular expression that must match the current function call stack trace (New in [1.51.1b5](https://github.com/gorhill/uBlock/commit/4649ae4d78)). Prepend pattern with `!` to test for unmatched patterns in stack trace <sup>(New in [1.51.1b6](https://github.com/gorhill/uBlock/commit/84cc69aa10bc9c8045ed94b528ddc158c06ae7ab))</sup>
A property in a list of properties can be a chain of properties, example: `adpath.url.first`.
After [1.28.0](https://github.com/gorhill/uBlock/commit/f433932d8602230539d3408e9946d4d70b40306c), two special _"wildcard tokens"_ have been added:
- `[]`: iterate in all elements in an array. To deal with cases where the
property to remove is an element in an array.
To remove `adserver` object properties from array in following JSON payload:
{"playlist": [{"adserver": "first"},{"adserver": "second"}]}
Use:
+js(json-prune, playlist.[].adserver)
- `*`: iterate through all own properties of an object. For example, to deal with hard to predict random-named properties.
To remove `adserver` object properties from inside _randomly named_ objects in following JSON payload:
{"playlist": {"random1": {"adserver": "first"}, "randomB": {"adserver": "second"}}}
Use:
+js(json-prune, playlist.*.adserver)
Version [1.57.0](https://github.com/gorhill/uBlock/commit/e7a0f8c7810c002bc7cec6a1160f8b091f8ea52e) extend syntax with two special token properties:
- `[-]`: remove an array entry if part right of `[-]` matches the
inspected item.
- `{-}`: remove a property if part right of `{-}` matches the
inspected item.
When used without parameters, will log current hostname + json payload to the logger.
New in [1.27.0](https://github.com/gorhill/uBlock/commit/578594bbd7c545b62f18267d640a605f8e07a53a) - second parameter can be used to limit logging to JSON payloads which stringified content match specified string or _regular expression_.
Tokens:
- `log, ...`: This extends logging capabilities of `json-prune` scriptlet as follows: `...##+js(json-prune, a, b, stackNeedle, log, [logneedle], logstack, 1)`. Whereas before, the only way to log `json-prune` usage was to skip providing the property chain: `...##+js(json-prune, , b)` Where `b` was the expression to filter out logging output. With the extended logging capabilities, the logging output can be filtered out with `logneedle`, which can be a regex literal. Additionally, to log the stack trace the `stackNeedle` argument must be set to non-empty string. You can use `/.^/` to log the stack trace without matching it (New in [1.51.1b5](https://github.com/gorhill/uBlock/commit/81b2fcee5d)).
Examples:
- `youthhealthmag.com##+js(json-prune, unit_list)`
- `winfuture.de##+js(json-prune, adtagparameter, enabled)`
- `imgsen.com##+js(json-prune, *, showTrkURL)` - will remove everything when needle matches, new in [1.35](https://github.com/gorhill/uBlock/commit/d338e4c4b6caf339873a60c9d48fde58e9a495ce)
If the site uses `eval` in lieu of `JSON.parse`, see: [evaldata-prune](#evaldata-prunejs-)
Also see:
- [AdGuard `json-prune`](https://github.com/AdguardTeam/Scriptlets/blob/master/wiki/about-scriptlets.md#json-prune)
***
### json-prune-fetch-response.js [↪](https://github.com/gorhill/uBlock/blob/66e3a1ad47162a89709e99072e5eaecdd83cb633/assets/resources/scriptlets.js#L1229)
New in [1.51.1rc1](https://github.com/gorhill/uBlock/commit/749cec0f095f659d6c0b90eb89b729e9deb07c87)
Removes specified properties from the JSON response of a fetch call.
Syntax:
...##+js(json-prune-fetch-response, prune paths [, needle paths [, ...varargs ]]) ```
For parameters, see: json-prune
Except that the stack parameter is treated as a vararg.
Tokens:
- "propsToMatch": string of space-separated properties to match; possible props:
- string or regular expression for matching the URL passed to fetch call;
- colon-separated pairs
name:valuewherenameisinitoption namevalueis string or regular expression for matching the value of the option passed to fetch call.
- "stackToMatch": string or regular expression that must match the current function call stack trace. Prepend pattern with
!to test for unmatched patterns in stack trace.
