Updated "no-fetch-if" scriptlet + added "trusted-suppress-native-method" scriptlet.

garry-ut99 2024-07-19 15:14:59 +00:00
parent 7d212d6df5
commit 43d4ec7045

@ -23,6 +23,7 @@
- [trusted-click-element](#trusted-click-elementjs-) [Trusted]
- [set-constant](#set-constantjs-) _(set)_
- [trusted-set-constant](#trusted-set-constantjs-) _(trusted-set)_ [Trusted]
- [trusted-suppress-native-method](#trusted-suppress-native-methodjs-) _(trusted-set)_ [Trusted]
- [set-cookie](#set-cookiejs-)
- [trusted-set-cookie](#trusted-set-cookiejs-) [Trusted]
- [remove-cookie](#remove-cookiejs-) _(cookie-remover)_
@ -653,6 +654,10 @@ Parameters:
- optional, space-separated list of conditions which must be ALL fulfilled in order for the defusing to take place:
- string/_regular expression_ matching in URL passed to `fetch()` call
- colon-separated `name:value` pairs of [`init` option name](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) and string/_regular expression_ matching in value of that option passed to `fetch()` call.
- optional, (new in [1.58.1rc4](https://github.com/gorhill/uBlock/commit/e785b99338)), string for defining response type / JSON string with
properties to set on the returned response instance, original response type is used if not specified:
- `ok`, supported values: `false`, `true`
- `type`, supported values: `"basic"`, `"cors"`, `"opaque"`
When used without parameters, the parameters passed to `no-fetch-if` will be logged to the console, as `uBO: fetch([...list of arguments...])`.
@ -1247,6 +1252,61 @@ Also see:
***
### trusted-suppress-native-method.js [](https://github.com/gorhill/uBlock/blob/97d11c03c20bdc15877c342c404f179ca5c63ff6/assets/resources/scriptlets.js#L4838)
#### _Trusted scriptlet_
New in [1.58.1rc0](https://github.com/gorhill/uBlock/commit/97d11c03c2)
This is a first draft version with current limitations:
- Does not support matching arguments which are object or array
- Does not support `stack` parameter
Syntax:
- `example.org#%#//scriptlet('trusted-suppress-native-method', methodPath, signatureStr[, how[, stack]])`
Parameters:
- methodPath required, string path to a native method (joined with `.` if needed). The property must be attached to `window`.
- signatureStr required, string of `|`-separated argument matchers. Supported value types with corresponding matchers:
- string exact string, part of the string or regexp pattern. Empty string `""` to match an empty string. Regexp patterns inside object matchers are not supported.
- number, boolean, null, undefined exact value,
- object partial of the object with the values as mentioned above, i.e by another object, that includes property names and values to be matched,
- array partial of the array with the values to be included in the incoming array, without considering the order of values.
To ignore specific argument, explicitly use whitespace as a matcher, e.g `' | |{"prop":"val"}'` to skip matching first and second arguments.
If `signatureStr` parameter is not declared, the scriptlet will log all calls to `methodPath` along with the arguments passed and will not prevent the trapped method.
Tokens:
- "how": optional, string, one of the following:
- `abort` default, aborts the call by throwing an error,
- `prevent` replaces the method call with the call of an empty function.
- "stack": optional, string or regular expression that must match the current function call stack trace.
Examples:
```adblock
example.org##+js(trusted-suppress-native-method, localStorage.setItem, '/key/|"value"', prevent)
example.org##+js(trusted-suppress-native-method, Object.prototype.hasOwnProperty, '"test"')
example.org##+js(trusted-suppress-native-method, Node.prototype.appendChild, '{"id":"str"}', prevent)
example.org##+js(trusted-suppress-native-method, Document.prototype.querySelectorAll, '"div"')
example.org##+js(trusted-suppress-native-method, Array.prototype.concat, '[1, "str", true]')
example.org##+js(trusted-suppress-native-method, sessionStorage.setItem, ' |"item-value"', abort, someFuncName)
```
1. Prevent `localStorage.setItem('test-key', 'test-value')` call matching first argument by regexp pattern and the second one by substring.
2. Abort `obj.hasOwnProperty('test')` call matching the first argument.
3. Prevent `Node.prototype.appendChild` call on element with the id `test-id` by object matcher.
4. Abort all `document.querySelectorAll` calls with `div` as the first argument.
5. Abort `Array.prototype.concat([1, 'str', true, null])` calls by matching array argument contents.
6. Use stack argument to match by the call, while also matching the second argument.
Also see: [AdGuard `trusted-suppress-native-method`](https://github.com/AdguardTeam/Scriptlets/blob/master/wiki/about-trusted-scriptlets.md#trusted-suppress-native-method)
[Documentation to be completed]
***
### set-cookie.js [](https://github.com/gorhill/uBlock/blob/4649ae4d78fa7d46e80d71d39d377d1b65309020/assets/resources/scriptlets.js#L2908)
New in [1.50.1b0](https://github.com/gorhill/uBlock/commit/27a54c084556f657522b06484d2e28b21e1fac5a).