|
1 | 1 | # <a id="trusted-scriptlets"></a> Available Trusted Scriptlets |
2 | 2 |
|
3 | 3 | - [trusted-click-element](#trusted-click-element) |
| 4 | +- [trusted-prune-inbound-object](#trusted-prune-inbound-object) |
4 | 5 | - [trusted-replace-fetch-response](#trusted-replace-fetch-response) |
5 | 6 | - [trusted-replace-node-text](#trusted-replace-node-text) |
6 | 7 | - [trusted-replace-xhr-response](#trusted-replace-xhr-response) |
@@ -100,6 +101,86 @@ and each of them should match the syntax. Possible `name`s: |
100 | 101 |
|
101 | 102 | * * * |
102 | 103 |
|
| 104 | +## <a id="trusted-prune-inbound-object"></a> ⚡️ trusted-prune-inbound-object |
| 105 | +
|
| 106 | +> Added in unknown. |
| 107 | +
|
| 108 | +Removes listed properties from the result of calling specific function (if payload contains `Object`) |
| 109 | +and returns to the caller. |
| 110 | +
|
| 111 | +Related UBO scriptlet: |
| 112 | +https://github.com/gorhill/uBlock/commit/1c9da227d7 |
| 113 | +
|
| 114 | +### Syntax |
| 115 | +
|
| 116 | +```text |
| 117 | +example.org#%#//scriptlet('trusted-prune-inbound-object', functionName[, propsToRemove [, obligatoryProps [, stack]]]) |
| 118 | +``` |
| 119 | + |
| 120 | +- `functionName` — required, the name of the function to trap, it must have an object as an argument |
| 121 | +- `propsToRemove` — optional, string of space-separated properties to remove |
| 122 | +- `obligatoryProps` — optional, string of space-separated properties |
| 123 | + which must be all present for the pruning to occur |
| 124 | +- `stack` — optional, string or regular expression that must match the current function call stack trace; |
| 125 | + if regular expression is invalid it will be skipped |
| 126 | + |
| 127 | +> Note please that you can use wildcard `*` for chain property name, |
| 128 | +> e.g. `ad.*.src` instead of `ad.0.src ad.1.src ad.2.src`. |
| 129 | +
|
| 130 | +### Examples |
| 131 | + |
| 132 | +1. Removes property `example` from the payload of the Object.getOwnPropertyNames call |
| 133 | + |
| 134 | + ```adblock |
| 135 | + example.org#%#//scriptlet('trusted-prune-inbound-object', 'Object.getOwnPropertyNames', 'example') |
| 136 | + ``` |
| 137 | +
|
| 138 | + For instance, the following call will return `['one']` |
| 139 | +
|
| 140 | + ```html |
| 141 | + Object.getOwnPropertyNames({ one: 1, example: true }) |
| 142 | + ``` |
| 143 | +
|
| 144 | +2. Removes property `ads` from the payload of the Object.keys call |
| 145 | +
|
| 146 | + ```adblock |
| 147 | + example.org#%#//scriptlet('trusted-prune-inbound-object', 'Object.keys', 'ads') |
| 148 | + ``` |
| 149 | +
|
| 150 | + For instance, the following call will return `['one', 'two']` |
| 151 | +
|
| 152 | + ```html |
| 153 | + Object.keys({ one: 1, two: 2, ads: true }) |
| 154 | + ``` |
| 155 | +
|
| 156 | +3. Removes property `foo.bar` from the payload of the JSON.stringify call |
| 157 | +
|
| 158 | + ```adblock |
| 159 | + example.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', 'foo.bar') |
| 160 | + ``` |
| 161 | +
|
| 162 | + For instance, the following call will return `'{"foo":{"a":2},"b":3}'` |
| 163 | +
|
| 164 | + ```html |
| 165 | + JSON.stringify({ foo: { bar: 1, a: 2 }, b: 3 }) |
| 166 | + ``` |
| 167 | +
|
| 168 | +4. Removes property `foo.bar` from the payload of the JSON.stringify call if its error stack trace contains `test.js` |
| 169 | +
|
| 170 | + ```adblock |
| 171 | + example.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', 'foo.bar', '', 'test.js') |
| 172 | + ``` |
| 173 | +
|
| 174 | +5. Call with only first and third argument will log the current hostname and matched payload at the console |
| 175 | +
|
| 176 | + ```adblock |
| 177 | + example.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', '', 'bar', '') |
| 178 | + ``` |
| 179 | +
|
| 180 | +[Scriptlet source](../src/scriptlets/trusted-prune-inbound-object.js) |
| 181 | +
|
| 182 | +* * * |
| 183 | +
|
103 | 184 | ## <a id="trusted-replace-fetch-response"></a> ⚡️ trusted-replace-fetch-response |
104 | 185 |
|
105 | 186 | > Added in v1.7.3. |
|
0 commit comments