1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-19 19:52:51 +02:00
Commit Graph

255 Commits

Author SHA1 Message Date
Raymond Hill
6e78ee096a
Fix handling of empty strings for set/set-attr scriptlets
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2729
2023-07-11 15:10:27 -04:00
Raymond Hill
786d9b2212
Add set-attr scriptlet
Reference:
- https://github.com/AdguardTeam/Scriptlets/blob/master/src/scriptlets/set-attr.js

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2347
2023-07-06 08:51:31 -04:00
Raymond Hill
fea6f7f311
Do not bail too early when trapping properties in acs scriptlet
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2130#issuecomment-1621684566
2023-07-05 10:00:31 -04:00
Raymond Hill
083a318090
Add set-session-storage-item scriptlet
Reference:
- https://github.com/AdguardTeam/Scriptlets/blob/master/src/scriptlets/set-session-storage-item.js
2023-07-04 07:13:22 -04:00
Raymond Hill
1f57822c33
Add Accept/Reject as valid values for set-cookie scriptlet
Related discussion:
- https://github.com/uBlockOrigin/uAssets/discussions/18762
2023-07-01 10:25:19 -04:00
Raymond Hill
e0b4b3d830
Add alias for scriptlet to increase compatibility with AdGuard filter lists 2023-07-01 10:20:23 -04:00
Raymond Hill
b283d6aa33
Add support to remove values in set-local-storage-item scriptlet
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2697#discussioncomment-6278359

When using the special value `$remove$`, the scriptlet will remove
the item from the local storage.
2023-06-30 09:03:17 -04:00
Raymond Hill
fd036a51ee
Add compatibility with AdGuard's #%#//scriptlet(...) syntax
Related issue:
- https://github.com/AdguardTeam/Scriptlets/issues/332

Additionally, uBO's own scriplet syntax now also accept quoting
the parameters with either `'` or `"`. This can be used to avoid
having to escape commas when they are present in a parameter.
2023-06-28 19:35:22 -04:00
Raymond Hill
e0b3b44080
Skip regex-testing context when no context provided
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/18725

Testing the context was causing the deprecated static property
RegExp.$1 to be clobbered, causing webpage breakage because this
property was subsequently used used by the caller.
2023-06-28 18:12:17 -04:00
Raymond Hill
ea4afc0610
Minor code review of set-local-storage-item scriptlet 2023-06-23 08:23:08 -04:00
Raymond Hill
9443ba80a0
Add set-local-storage-item/trusted-set-local-storage-item scriptlets
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2697
2023-06-20 10:59:48 -04:00
Raymond Hill
7901a00bd7
Fix handling of path in set-cookie scriptlet
As per feedback from filter list volunteers.
2023-06-18 15:13:54 -04:00
Raymond Hill
bd7318da3c
Fix m3u-prune scriptlet
Related issue:
- https://www.reddit.com/r/uBlockOrigin/comments/14cbznu/foxcom_ssai_workaround/
2023-06-18 14:29:11 -04:00
Raymond Hill
0bd4b600cf
Rework nowoif scriptlet
New official name: `no-window-open-if`.

The pattern will now be matched against all arguments passed
to `window.open()`: all the arguments are joined as a single
space-spearated string, and the result is used as the target
for matching the pattern.

To enable logging, used the extra parameters approach, i.e.
`log, 1`, which should come after the positional arguments
`pattern`, `delay`, and `decoy`.
2023-06-17 11:53:08 -04:00
Raymond Hill
112e41b9d5
Fine tune new set-cookie/trusted-set-cookie scriptlet
Added support for extra parameter `reload, 1`. If present,
the scriplet will force a reload of the webpage if the cookie
being set was not already set.

As per feedback from filter list maintainers.
2023-06-16 11:32:12 -04:00
Raymond Hill
5d596b644d
Remove stray whitespaces 2023-06-15 20:00:57 -04:00
Raymond Hill
eaea26b5e9
Add trusted-set-cookie scriptlet
This new scriptlet is only valid when used in a trusted lists.

Implementation follows:
https://github.com/AdguardTeam/Scriptlets/blob/master/src/scriptlets/trusted-set-cookie.js
2023-06-15 19:57:10 -04:00
Raymond Hill
27a54c0845
Add set-cookie scriptlet
This new scriptlet is only valid when used in a trusted lists.

Implementation follows:
https://github.com/AdguardTeam/Scriptlets/blob/master/src/scriptlets/set-cookie.js#L16
2023-06-15 11:08:35 -04:00
Raymond Hill
f8c4b8e52d
Add support to remove attributes in xml-prune scriptlet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/18244
2023-06-05 08:51:20 -04:00
Raymond Hill
f3b720d532
Improve href-sanitizer scriptlet 2023-05-30 09:13:46 -04:00
Raymond Hill
56e1d92dbd
Fix/improve scriptlets
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2678
- https://github.com/uBlockOrigin/uAssets/issues/18278
2023-05-30 08:38:35 -04:00
Raymond Hill
2a3a796d33
Minor fix 2023-05-29 15:05:50 -04:00
Raymond Hill
a1a3477b07
Fix oversight in last commit 2023-05-29 14:54:13 -04:00
Raymond Hill
c8de904191
Add evaldata-prune scriptlet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/18278
2023-05-29 14:37:02 -04:00
Raymond Hill
3ee3275dc1
Harden addEventListener scriptlet 2023-05-28 14:56:31 -04:00
Raymond Hill
82eee10c3a
Logging-related changes 2023-05-28 10:37:23 -04:00
Raymond Hill
3c9e946107
Log error in dev console is logging is enabled 2023-05-27 19:05:02 -04:00
Raymond Hill
8ed78cfb23
Support pruning by xpath in xml-prune scriptlet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/18244
2023-05-27 17:26:19 -04:00
Raymond Hill
d3fae27017
Add support for xhr in xml-prune
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/18244
2023-05-27 09:14:19 -04:00
Raymond Hill
2bb446797a
Add remove-node-text.js scriptlet
The scriptlet remove the *whole* text of a DOM node. Usage:

    example.com##+js(remote-node-text, nodeName, condition, ...)

Where `condition` is a pattern to find in the target node for the
removal to occur. Since the text of the node is wholly removed,
this is not a scriplet which requires a trusted-source, as it is
virtually a similar capability as removing DOM nodes through
procedural cosmetic operator `:remove()` (which can't target
`#text` nodes), which does not require trusted-source.

Alias: `rmnt`

The extra parameters are the same as those documented for
`replace-node-text`.

For consistency, the alias for `replace-node-text` has been renamed
`rpnt`.
2023-05-25 08:51:26 -04:00
Raymond Hill
796ebc2444
Fix spoof-css for Firefox 2023-05-24 16:50:34 -04:00
Raymond Hill
005a0fe95d
Comment 2023-05-24 15:56:42 -04:00
Raymond Hill
e33d948fdc
Minor code review 2023-05-24 15:33:46 -04:00
Raymond Hill
db7cadae49
Remove pointless code in spoof-css scriptlet 2023-05-24 15:26:57 -04:00
Raymond Hill
d4fb87b6ba
Properly return inherited methods in property getter in spoof-css scriptlet
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2618#issuecomment-1561451479
2023-05-24 14:58:12 -04:00
Raymond Hill
1d9ee00498
Simplify passing extra parameters in scriptlets
When scriptlets can receive extra optional paramaters, these will
now be passed as pair of extra paramaters in the filter declaration,
whereas each pair is a `name, value` instance.

As a result, the optional paramaters that can be passed to the
`aeld` scriptlet can be passed this way, i.e. no longer need
a JSON approach, example:

    github.com##+js(aeld, click, , log, 1)
    github.com##+js(aeld, , , runAt, idle, log, 1)

The non-optional paramaters are always positional, after which
the optional paramaters are non-positional pairs of values.
2023-05-24 11:59:17 -04:00
Raymond Hill
8d1669f9b5
Ensure document.documentElement is present when executing acs scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2670
2023-05-24 10:32:03 -04:00
Raymond Hill
879b837669
Fix scriptlet alias 2023-05-23 17:58:20 -04:00
Raymond Hill
842e356610
Put back missing scriptlet dependency
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2668

This broke `set-constant` filters.
2023-05-23 17:03:30 -04:00
Raymond Hill
19cdd50a1c
Add trusted-set-constant scriptlet
Alias: `trusted-set`

Behaves exactly like set-constant, except that any arbitrary JSON-
compatible value can be set.

By default the value is treated as a string, which can be anything.

If the value starts with `{` and ends with `}`, the value will be
JSON-parsed, and the `value` property of the resulting object will
be used.

As with any scriptlet requiring trust, filters using
`trusted-set-constant` can only come from trusted filter lists,
otherwise they are discarded.

Related discussion:
- https://github.com/uBlockOrigin/uAssets/discussions/18185#discussioncomment-5977456
2023-05-23 10:59:27 -04:00
Raymond Hill
824f8b7ceb
Add comments for reviewers 2023-05-23 09:03:19 -04:00
Raymond Hill
1a863a877d
Support injecting scriptlet in MAIN or ISOLATED world
This reflects the _world_ of the MV3 scripting API:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/ExecutionWorld

MAIN: page's world
ISOLATED: extension's content script world

Some scriptlets are best executed in either world, so this
commit allows to pick in which world a scriptlet should execute
(default to MAIN).

For instance, the new sed.js scriptlet will now execute in
the ISOLATED world.
2023-05-22 20:19:00 -04:00
Raymond Hill
659f35837a
Imrpove sed scriptlet reliability
Related feedback:
- https://github.com/uBlockOrigin/uAssets/discussions/18185
2023-05-22 15:33:47 -04:00
Raymond Hill
99ce027fd7
Review default behavior of new sed.js scriptlet
Related commit:
- 41876336db

The `tryCount` parameter has been removed.

The new default behavior of the sed.js scriptlet is to bail out
when the document itself has been fully loaded, i.e. when
DOMContentLoaded event is fired.

Two new parameters have been added to override the default quit out
behavior:

`stay, 1`

Use to force the scriptlet to stay at work forever.

`quitAfter, ms`

This tells the scriptlet to quit `ms` milliseconds after the
page has been loaded, i.e. after the DOMContentLoaded event has
been fired.

The mutation observer of the sed.js scriptlet can be a significant
overhead for pages with dynamically updated DOM, and in most cases
the scriptlet is useful only for DOM changes occurring before the
DOMContentLoaded event, so the default is to quit out when that
event is received ("quit out" means discarding the mutation observer
and having the scriptlet garbage-collected by the JS engine).
2023-05-22 10:26:09 -04:00
Raymond Hill
41876336db
Add trusted-source support for privileged scriptlets
At the moment, the only filter lists deemed from a "trusted source"
are uBO-specific filter lists (i.e. "uBlock filters -- ..."), and
the user's own filters from "My filters".

A new scriptlet which can only be used by filter lists from trusted
sources has been introduced: `sed.js`.

The new `sed.js` scriptlet provides the ability to perform
text-level substitutions. Usage:

    example.org##+js(sed, nodeName, pattern, replacement, ...)

`nodeName`

The name of the node for which the text content must be substituted.
Valid node names can be found at:
https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName

`pattern`

A string or regex to find in the text content of the node as the target of
substitution.

`replacement`

The replacement text. Can be omitted if the goal is to delete the text which
matches the pattern. Cannot be omitted if extra pairs of parameters have to be
used (see below).

Optionally, extra pairs of parameters to modify the behavior of the scriptlet:

`condition, pattern`

A string or regex which must be found in the text content of the node
in order for the substitution to occur.

`sedCount, n`

This will cause the scriptlet to stop after n instances of substitution. Since
a mutation oberver is used by the scriptlet, it's advised to stop it whenever
it becomes pointless. Default to zero, which means the scriptlet never stops.

`tryCount, n`

This will cause the scriptlet to stop after n instances of mutation observer
run (regardless of whether a substitution occurred). Default to zero, which
means the scriptlet never stops.

`log, 1`

This will cause the scriptlet to output information at the console, useful as
a debugging tool for filter authors. The logging ability is supported only
in the dev build of uBO.

Examples of usage:

    example.com##+js(sed, script, /devtoolsDetector\.launch\(\)\;/, , sedCount, 1)

    example.com##+js(sed, #text, /^Advertisement$/)
2023-05-21 14:16:56 -04:00
Raymond Hill
d405460584
Add spoof-css scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2618

Usage:

    example.com##+js(spoof-css, selector, property-name, property-value, ...)

- selector: a valid CSS selector which matches the elements for which
  the spoofing must apply.
- property-name: a CSS property name (can be dashed- or camel-cased)
- property-value: the value to return regardless of the currently
  computed value.

There can be any number of property-name/property-value pairs, all
separated by commas.

A special property-name/property-value pair `debug/1` can be used
to force the browser to break when `getComputedStyle()` or
`getBoundingClientrect()` is called, useful to help pinpoint usage
of those calls in the page's source code:

    example.com##+js(spoof-css, .ad, debug, 1)
2023-05-20 17:18:44 -04:00
Raymond Hill
2ef2888805
Expand/harden some scriptlets
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2615

Expand `set-constant`: 3rd parameter and beyond are tokens which
modify the behavior of `set-contant`. Valid tokens:

- `interactive`, `end`, `2`: set the constant when the event
  `DOMContentInteractive` is fired.
- `complete`, `idle`, `3`: set the constant when the event
  `load` is fired.
- `asFunction`: the constant will be a function returning the
  specified value.
- `asCallback`: the constant will be a function returning a
  function returning the specified value.
- `asResolved`: the constant will be a promise resolving to
  the specified value.
- `asRejected`: the constant will be a promise failing with
  the specified value.

Harden `no-setimeout-if` and `no-setinterval-if` as per feedback
from filter list maintainers.
2023-05-19 12:55:01 -04:00
Raymond Hill
df5437a54f
Revert "Render List stats below on mobile"
This reverts commit 9ea39886b6.
2023-05-17 15:44:11 -04:00
Raymond Hill
9ea39886b6
Render List stats below on mobile 2023-05-16 12:10:40 -04:00
Raymond Hill
6c29ae82f2
Protect against possible page modification to addEventListener 2023-04-28 07:58:23 -04:00
Raymond Hill
3c12173dfe
Add ability to execute aeld scriptlet at a later time
As per discussion with filter list maintainers.

THis requires to use JSON notation for parameter passing:

- "runAt":  "end" = execute scriptlet at `DOMContentLoaded` event
- "runAt": "idle" = execute scriptlet at `load` event
2023-04-27 12:52:17 -04:00
Raymond Hill
349c8ca619
Fix overzealous logging in acs scriptlet 2023-04-23 09:28:59 -04:00
Raymond Hill
cc062d3a8a
No need for redundant "safe" 2023-04-15 11:14:14 -04:00
Raymond Hill
e1500ee88d
Add ability to defer set-constant execution
A new optional parameter has been added to `set-constant`
scriptlet: `runAt`, default to `0`.

 ..##+js(set, document.body.oncontextmenu, null, 2)

When the `runAt` parameter is present, uBO will take it into
account to possibly defer execution of `set-constant`:

- `runAt` not present: execute immediately
- `runAt` = 1: execute immediately
- `runAt` = 2: execute when document state is "interactive"
- `runAt` = 3: execute when document state is `"complete"
2023-04-11 21:45:40 -04:00
Raymond Hill
edbe96a401
Add logging ability to acs scriptlet, for the benefit of filter list
maintainers.

To enable logging, use the JSON approach to pass parameters to
`acs` scriptlet. Example:

    ..##+js(acs, { "target": "document.oncontextmenu", "log": true })

Whereas "target", "needle", and "context" correspond to their
respective positional argument. Using JSON form to pass parameters
allows to specify extra paramters to facilitate debugging of that
scriptlet:

- `"log": true` => output useful information at the dev console.
- `"debug": true` => break at key locations in the scriptlet.

The added logging/debugging capabilities work only in the dev build
of uBO or if the advanced setting `filterAuthorMode` is set to
`true`.
2023-04-02 12:01:58 -04:00
Raymond Hill
b5d78a07bf
Fix type in variable name
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2570
2023-03-30 20:46:44 -04:00
Raymond Hill
c8af55e27a
Harden aeld scriptlet against page's tampering
Related feedback:
- https://github.com/uBlockOrigin/uBlock-discussions/discussions/1#discussioncomment-5433222
2023-03-26 14:02:21 -04:00
Raymond Hill
5c9c87e485
Add ability for scriptlets to share local data
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1741

As a result of the new capability, usage of RegExp API in `aost`
scriptlet has been shielded from the webpage tampering with the
API.
2023-03-26 12:31:36 -04:00
Raymond Hill
236fb3ad59
Add scriptlet dependencies to reduce code duplication 2023-03-26 09:13:17 -04:00
Raymond Hill
439951824a
Remove addEventListenerLogger, expand addEventListenerDefuser
The scriptlet addEventListenerLogger has been removed.

The logging of addEventListener() calls can now be done with the
addEventListenerDefuser scriptlet, which now supports the
following named arguments:

"type": the event type to match. Default to '', i.e. match-all.

"pattern": the pattern to match against the handler argument
Default to '', i.e. match-all.

"log": an integer value telling when to log:

- 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()

"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.

The usage of named arguments is optional, positional arguments
are still supported as documented. Named arguments is required
to use "log" and/or "debug" arguments.

Obviously, do not use "log" or "debug" in any filter list, these
are investigative tools for filter list authors.

Examples of usage using named arguments:

  wikipedia.org##+js(aeld, { "type": "/mouse/", "pattern": "/.^/", "log": 2 })

Above 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).

  wikipedia.org##+js(aeld, { "type": "/.^/", "log": 2 })

Above filter will log all calls without defusing any of them
(because type can't match anything)

  wikipedia.org##+js(aeld, { "log": 1 })

Above filter will log and defuse all calls to addEventListener().
2023-03-25 12:35:56 -04:00
Raymond Hill
a51130baed
Remove unused scriptlets 2023-03-24 18:46:39 -04:00
Raymond Hill
18a84d2819
Refactor scriptlets injection code
Builtin scriptlets are no longer parsed as text-based resources,
they are imported as JS functions, and `toString()` is used to
obtain text-based representation of a scriptlet.

Scriptlet parameters are now passed as function call arguments
rather than by replacing text-based occurrences of `{{i}}`. The
arguments are always string values (see below for exception).

Support for argument as Object has been added. This opens the
door to have scriptlets using named arguments rather than
positional arguments, and hence easier to extend functionality
of existing scriptlets. Example:

    example.com##+js(scriplet, { "prop": "adblock", "value": false, "log": true })

Compatibility with user-provided scriptlets has been preserved.

User-provided scriptlets can benefit some of the changes:

Use the form `function(..){..}` instead of `(function(..){..})();`
in order to received scriptlet arguments as part of function call
-- instead of using `{{i}}`.

If using the form `function(..){..}`, you can choose to receive
an Object as argument -- just be sure that your scriptlet's
parameter is valid JSON notation.
2023-03-24 14:05:18 -04:00
Raymond Hill
e93117cbb6
Add call-nothrow scriptlet
The purpose is to prevent a call to an existing function from
throwing an exception. 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.
2023-03-14 18:50:01 -04:00
Raymond Hill
fc84fdee52
Fine tune scriptlet 2023-03-14 08:21:22 -04:00
Raymond Hill
b3821e6869
Support removing whole lines of text with regex in m3u-prune scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2508

If the first argument is a regex with multine flag set, the
scriptlet will execute the regex against the whole text, and
remove matching text from the whole text.

If the matching text does not contains whole lines, the text
won't be removed, i.e. it is not allowed to remove only part
of a line.
2023-03-12 17:45:02 -04:00
Raymond Hill
4b4ef6a60c
Rename href-from-text to href-sanitizer, add argument
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2531#issuecomment-1462389539

Usage:
- example.com##+js(href-sanitizer, a[href^="/go?to="]:not([title]))
- example.com##+js(href-sanitizer, a[href^="/go?to="][title], [title])

The second argument is the attribute from which to extract the text
to be used for the `href` attribute of the link. If the second
attribute is absent, the text content of the element will be used.
2023-03-09 13:37:06 -05:00
Raymond Hill
e123256eaf
Add experimental href-from-text scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2531

Usage:

    example.com##+js(href-from-text, a[href^="/tracker-link?to="]

The above scriptlet will find all elements matching the selector
passed as 1st argument, and replace the `href` attribute with the
text content of the element, if all the following conditions are
met:

- The element is a link (`a`) element
- The link element has an existing `href` attribute
- The text content of the element is a valid `https`-based URL
2023-03-09 08:49:26 -05:00
Raymond Hill
2f646dbdb0
Pull reference Easylist assests from own repo 2022-10-24 12:37:04 -04:00
Raymond Hill
ec83127f6c
Update m3u-prune scriptlet 2022-09-26 22:37:11 -04:00
Raymond Hill
115f7bb687
Fix operator token-to-ctor map
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2294
2022-09-26 22:27:50 -04:00
Raymond Hill
6828e1c3b2
Bail out early if missing required argument 2022-09-25 06:57:51 -04:00
Raymond Hill
596145ceb9
Harden xml-prune scriptlet 2022-09-25 06:49:41 -04:00
Raymond Hill
bf690145c4
Add new scriptlet: xml-prune
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/14849

Arguments:

1. Required. The selector of elements which are to be removed.
   Example: Period[id*="-roll-"][id*="-ad-"]

2. An optional selector that must have a match in the document
   for the pruning to occur. No selector means the pruning can
   be performed regardless.

3. An optional URL which must be a match for the pruning to
   occur. If left blank, the pruning can be performed regardless.
2022-09-24 20:49:00 -04:00
Raymond Hill
65a0561072
Slightly change behavior of window-close-if scriplet
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2270

If the argument to the window-close-if scriptlet is a regex, the
match will be against the whole location URL, otherwise the
match will be against the part+query part of the location URL.
2022-09-17 12:46:42 -04:00
Raymond Hill
78fccadaf2
Fix bad alias
Related feedback:
- https://github.com/DandelionSprout/adfilt/issues/63#issuecomment-1214131551
2022-08-13 09:09:36 -04:00
Raymond Hill
9d81b7c4d9
Skip testing context when none present in acis scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2154
2022-06-24 13:35:20 -04:00
Raymond Hill
b76d7c6af6
Also dispatch loadend event in case of match
Related issue:
- https://github.com/AdguardTeam/Scriptlets/issues/199
2022-05-08 11:22:32 -04:00
Raymond Hill
8d7469afcf
Fix typo 2021-12-13 14:28:39 -05:00
Raymond Hill
c198b9a748
Add window.close scriptlet
Related feedback:
- https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847

AdGuard's rationale:
- https://github.com/AdguardTeam/Scriptlets/issues/158
2021-12-13 08:14:30 -05:00
Raymond Hill
b3f1f75389
Update twitch scriptlet as suggested
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1789#issuecomment-969416887
2021-11-16 07:22:06 -05:00
Raymond Hill
ddd31f3567
Update twitch-videoad.js scriptlet
Related commit:
- aad8946dab

Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1789#issuecomment-962440694
2021-11-14 13:55:34 -05:00
Raymond Hill
3f47172473
Update Twitch scriptlet
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1789#issuecomment-959831926

Related commit:
- 7233b5fd22
2021-11-04 09:24:31 -04:00
pixeltris
cc0008df57
Fix broken twitch.tv functionality (#3858)
* Fix broken twitch.tv functionality

Fixes some features of twitch.tv which are broken due to device id change on every gql request.

Related issues:
- https://github.com/pixeltris/TwitchAdSolutions/issues/50
- https://github.com/pixeltris/TwitchAdSolutions/issues/45

* Use strict equality
2021-10-14 10:03:25 -04:00
Raymond Hill
aceaea0122
Minor code review 2021-10-14 09:22:36 -04:00
Eli Grey
1285f78e05
Don't assume document.documentElement is non-null (#3857)
* Fix uBlockOrigin/uBlock-issues#1756

This PR fixes uBlockOrigin/uBlock-issues#1756.

* fix dom-inspector.js

* more explicit if statements

* these changes should also be safe
2021-10-14 09:08:08 -04:00
Raymond Hill
0d3a1932e9
Update twitch-videoad scriptlet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/5184#issuecomment-938379331

Solution contributed by <https://github.com/pixeltris>:
- 6be4c53130
2021-10-08 07:12:58 -04:00
Raymond Hill
c0a43b0d32
Add refresh-defuser scriptlet
To specifically defuse the reloading of a document through
a meta "refresh" tag.

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/

As per solution from AdGuard:
- https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/while_reading_a_sports_article_i_was_redirected/hf7wo9v/
2021-10-03 09:46:24 -04:00
Raymond Hill
33a18c3a1e
Convert fingerprint2.js scriptlet into a redirectable resource
As per internal discussion with volunteer filter list
maintainers.
2021-09-18 10:55:22 -04:00
Raymond Hill
745fbd1c02
Add no-xhr-if scriptlet
As per request from filter list maintainers.
2021-09-11 09:15:39 -04:00
Raymond Hill
5dd91211ae
Catch exceptions thrown Object.defineProperty
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/9883

Related commit:
- a9e6f9c72c
2021-09-01 18:25:20 -04:00
Raymond Hill
a9e6f9c72c
Assign value in set-constant regardless of configurable property
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1694
2021-08-27 10:48:49 -04:00
Raymond Hill
a21ecafbc6
Improve reliability of set-constant scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1694
2021-08-25 10:48:50 -04:00
Raymond Hill
4fe8126c66
Add ability to match against script content of data: URI
Related commit:
- ebc42ae21e
2021-07-18 08:50:57 -04:00
Raymond Hill
f07b1475a3
Fix hasty last commit 2021-07-17 14:27:37 -04:00
Raymond Hill
ebc42ae21e
Add abort-current-script scriptlet
This scriplet supersedes abort-current-inline-script (acis),
and accepts an optional third argument which is matched
against the `src` property of script resources.

When the third argument is not provided, the scriptlet
behaves essentially the same as `acis`, and because of
this `acis` is now aliased to `abort-current-script`, and
all existing `acis` filters will execute with no change
in behavior.

In the long run, usage of `abort-current-inline-script` or
its alias `acis` should go away and be replaced with
`abort-current-script` or its alias `acs`.
2021-07-17 14:03:50 -04:00
Raymond Hill
c91b4258e9
Put back mistakenly removed newline 2021-07-03 09:23:06 -04:00
Raymond Hill
35d7406214
Add asap behavior to remove-attr scriptlet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/9528
2021-07-03 09:19:24 -04:00
Raymond Hill
2de24a1184
Add ability to linger for remove-class scriptlet
Similar to related change for the `remove-attr` scriptlet:
- 0f330c7359

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/nsroaw/some_elements_isare_not_removed_after_the_cookie/
2021-06-06 08:58:40 -04:00
Raymond Hill
ce801b952b
Add empty array, object to set-constant scriptlet 2021-05-28 07:09:30 -04:00
Raymond Hill
07d3c96261
Fix potential exception when casting to string
Related discussion:
- https://github.com/uBlockOrigin/uAssets/issues/9123#issuecomment-848255120
2021-05-26 07:22:17 -04:00
Raymond Hill
e4b8f2ef2d
Ensure getter/setter are called with proper context
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/9110
2021-05-18 09:01:40 -04:00
Raymond Hill
bfdc81e9e4
Ensure FLoC is opt-in by default
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1553

This commit ensures FLoC is opt-in. The generic filter
`*##+js(no-floc)` in "uBlock filters -- Privacy" ensures
the feature is disabled when using default settings/lists.

Users can opt-in to FLoC by adding a generic exception
filter to their custom filters, `#@#+js(no-floc)`; or they
can opt-in only for a specific set of websites through a
more specific exception filter:

    example.com,shopping.example#@#+js(no-floc)
2021-04-11 09:36:56 -04:00
Raymond Hill
5a48917b80
Add no-floc scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1553
2021-04-11 07:11:09 -04:00
Raymond Hill
d338e4c4b6
Add support for "remove all properties" in json-prune scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1545
2021-04-06 10:12:34 -04:00
Raymond Hill
001f5a6500
Add any-delay to timeout/interval boosters
Using `*` as delay argument will match any
delay.

As per internal feedback from filter list
maintainers.
2021-01-23 09:45:44 -05:00
Raymond Hill
5fa873960f
Listen to load events on window, not document
Related feedback:
- 0f330c7359 (r45774155)
2021-01-08 13:11:09 -05:00
Raymond Hill
0f330c7359
Add ability to linger for remove-attr scriplet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1445

A third (optional) argument has been added to `remove-attr`
scriptlet, which can be one or more space-separated tokens
dictating the behavior of the scriptlet:

`stay`: This tells the scriplet to stay and act on DOM
changes, whiĺe the default behavior is to act only once
when the document becomes interactive.

`complete`: This tells the scriplet to start acting only
when the document is complete, i.e. once all secondary
resources have been loaded, while the default is to start
acting when the document is interactive -- which is earlier
than when the document is complete.

Example:

    ...##+js(remove-attr, class, .j-mini-player, stay)
2021-01-08 10:45:35 -05:00
Raymond Hill
ab06a01062
Better handle Request argument in no-fetch-if
As per internal feedback.
2020-12-24 08:26:30 -05:00
Raymond Hill
b6ed83bc5c
Add logging ability to new scriptlet no-fetch-if
When no-fetch-if scriptlet is used without argument, the
parameters passed to no-fetch-if will be output to the
console, as `uBO: fetch([...list of arguments...])`.
2020-12-11 09:28:29 -05:00
Raymond Hill
ba11a70013
Add new scriptlet: no-fetch-if
The new scriptlet allows to defuse calls to fetch() by returning
a promise which always resolve to an empty response.

There is only one argument, which is a space-separated list
of conditions which must be ALL fulfilled in order for the
defusing to take place.

Each condition is a pair of property name and property value
separated by a column. Valid property names are those
documented as valid `init` options:

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch

The URL of the fetch() is a special case and does not have to
be associated with a property name. Example of usage:

  ...##+js(no-fetch-if, method:HEAD)

Which means: defuse the call to fetch() if there is an
explicit option which contains `HEAD`. Another example:

  ...##+js(no-fetch-if, adsbygoogle.js)

Which means: defuse the call to fetch() if the URL contains
`adsbygoogle.js`. Multiple conditions can be provided:

  ...##+js(no-fetch-if, adsbygoogle.js method:HEAD)

If at least one condition does not match, the defusing will
not take place.

The string against which to match can be a literal regular
expression:

  ...##+js(no-fetch-if, /adsbygoogle.js$/ method:/HEAD|POST/)

Additonally, the following deprecated scriplets have been
removed:

- requestAnimationFrame-if.js
- setInterval-defuser.js
- setTimeout-logger.js
2020-12-11 08:29:23 -05:00
Raymond Hill
13f92756be
Make json-prune scriptlet also trap Response.json() calls
Related discussion:
- https://www.reddit.com/r/uBlockOrigin/comments/jns1t4/white_screen_skip_ad_on_youtube/gbg4aq8/
2020-11-08 08:45:33 -05:00
Raymond Hill
5de0ce9757
Improve fix for set-constant conflict
Related commit:
- 2546f39568
2020-10-20 05:23:10 -04:00
Raymond Hill
2546f39568
Avoid trapping already trapped properties
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/156#issuecomment-712249945

When the client code assigned a variable to itself, this
would cause the scriptlet to try to re-trap already
trapped properties.
2020-10-19 12:01:55 -04:00
Raymond Hill
a08f33e09d
Prevent only target (leaf) property from being overtaken
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/156#issuecomment-707095193

Related commit:
- 6e010ecc0f
2020-10-12 11:00:30 -04:00
Raymond Hill
6e010ecc0f
Prevent set-constant properties from being overtaken
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/156#issuecomment-707095193

Additionally, while investigating the issue I removed
code which is no longer needed since content scripts
are now injected in `about:blank` frames since 1.29.0.
2020-10-12 10:08:51 -04:00
pixeltris
75c58ec7af
Update for twitch.tv #5184 (#3781) 2020-10-02 12:20:30 -04:00
Raymond Hill
793e2c7896
Further fine tune new aost scriptlet 2020-09-23 09:41:00 -04:00
Raymond Hill
365b3f7f83
Changes to abort-on-stack-trace as per road testing
Related commit:
- https://github.com/gorhill/uBlock/commit/b735ac6b6aba
2020-09-23 06:54:44 -04:00
Raymond Hill
1e91fb8733
Fine tune regex used to detect inline script contexts
Related commit:
- b735ac6b6a
2020-09-22 11:18:12 -04:00
Raymond Hill
b735ac6b6a
Add abort-on-stack-trace scriptlet
This new scriplet has become necessary as a
countermeasure to new bypass mechanisms by
some websites, as discussed with filter list
maintainers.

Also related discussion:
https://github.com/AdguardTeam/Scriptlets/issues/82

Scriptlet: abort-on-stack-trace

Alias: aost

Argument 1:
  The property to trap in order to launch the
  stack trace matching code, ex. Math.random

Argument 2:
  The string (needle) to match against the stack
  trace. If the empty string, always match. There
  is a special string which can be used to match
  inline script context, <inline-script>.

Argument 3:
Whether to log, and if so how:
  Empty string: do not log
  1: log stack trace for all access to trapped
     property
  2: log stack trace for defused access to trapped
     property
  3: log stack trace for non-defused access to
     trapped property
2020-09-22 09:59:04 -04:00
Raymond Hill
953ba1231f
Object.values() may fail for unknown reasons
Work around this issue by using more reliable
Object.keys().
2020-09-11 08:30:11 -04:00
Raymond Hill
8275690e93
Fix https://github.com/uBlockOrigin/uAssets/issues/5696#issuecomment-675757755 2020-08-20 09:53:11 -04:00
Raymond Hill
c33de41660
Support multiple trappers to same property in set-constant
Related issues:
- https://github.com/uBlockOrigin/uBlock-issues/issues/156
- https://github.com/uBlockOrigin/uBlock-issues/issues/1162

Take into account that a trapped property may have been
already trapped, and if so honour previous trapper
getter/setter.
2020-07-19 08:16:40 -04:00
Raymond Hill
975d894419
Stringify argument using implicit rather than explicit conversion
Reported internally by team.

Explicit conversion was causing an exception to be
thrown when the type argument was not supporting
`toString()`, for example when `type` argument was
literal `null`.
2020-07-16 09:55:06 -04:00
Raymond Hill
8f3d8cde7a
Add support to compare delay against literal Number.NaN in nossif/nostif
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1136
2020-07-02 11:47:49 -04:00
Raymond Hill
f433932d86
Add support for wildcard/array in json-prune
Add support for specially-named properties:

`[]`, to iterate through all elements in an array, in
order to deal more graciously with cases where the
property to remove is an element in an array. An
actual case:

    +js(json-prune, playlist.movies.0.adserver playlist.movies.1.adserver ...)

Can be now converted to:

    +js(json-prune, playlist.movies.[].adserver)

`*`, to iterate through all own properties of an object,
in order to deal with random-named properties. For
example (not an actual case):

    +js(json-prune, playlist.*.adserver)

Where `adserver` would be a property member of an
object which is itself a property of `playlist`, but
which name is unknown or is variable.
2020-06-26 10:03:48 -04:00
Raymond Hill
c4d39d3763
Fix cookie removal on subdomains of base domain
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1126
2020-06-24 17:18:14 -04:00
Raymond Hill
5227013a8e
Add uBO: prefix to logged output in some scriptlets
As per request.
2020-04-28 11:19:26 -04:00
Raymond Hill
578594bbd7
Improve logging capabilities of json-prune scriptlet
Specifically:

- Log entries as received by client code
- Prettier and more readable console output
- Ability to only log entries matching a
  specific needle

As per internal discussion at
<https://github.com/uBlockOrigin/uAssets>; limited
logging capabilities of json-prune originally raised
by <https://github.com/gwarser>.
2020-04-28 09:47:03 -04:00
Raymond Hill
d95b27915f
Bring fingerprint2.js scriptlet up to date
Related issue:
- https://github.com/uBlockOrigin/uAssets/pull/4961
2020-04-18 09:45:07 -04:00
Raymond Hill
1de0e820b8
Replace requestAnimationFrame-if.js with no-requestAnimationFrame-if.js
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/981

To be consistent with no-setTimeout-if.js.

requestAnimationFrame-if.js is deprecated and must no longer be
used, it will be removed in the near future when it's no longer
in use in default filter lists.

no-requestAnimationFrame-if.js is aliased to norafif.js.
2020-04-15 10:06:53 -04:00
Raymond Hill
49d9929191
Add remove-class scriptlet (alias: rc)
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/935

Arguments are similar to that of remove-attr
scriptlet.
2020-03-18 09:44:18 -04:00
Raymond Hill
85cf8f5807
Fix last commit re. set-constant scriptlet
Related commit:
- https://github.com/gorhill/uBlock/commit/40ea9d69d5d0

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/947

Restore intended behavior with original commit:
- https://github.com/gorhill/uBlock/commit/14ebfbea279c

The purpose of the original change was to be able to
trap properties which values were `null`.
2020-03-16 09:09:48 -04:00
Raymond Hill
40ea9d69d5
Fix regression in set-constant scriptlet
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/947

`Object.prototype` is not an instance of `Object`, but
yet is still a JS object; thus the solution is to
additionally compare against `typeof`.
2020-03-16 08:47:34 -04:00
Raymond Hill
14ebfbea27
Improve set-constant.js scriptlet
The scriptlet will now still try to trap a specific
property if a segment of the chain is not undefined
while yet not an object either.

For example, this now allows to set a value on
`document.body.onselectstart` when `document.body` has
not been instantiated yet by the browser parser,
whereas this would previously fail because
`document.body` would be `null` while the scriptlet
was testing against `undefined`.
2020-03-07 14:16:54 -05:00
Raymond Hill
034c915f3b
Allow re-entrance in abort-current-inline-script
Related feedback:
- https://github.com/DandelionSprout/adfilt/issues/7#issuecomment-590391877

If a property is already trapped with a getter/setter,
propagate to these after validation succeed.
2020-02-24 13:40:17 -05:00
Raymond Hill
1a8571755e
Harden abort-current-inline-script scriplet
Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/6929
2020-02-09 10:35:18 -05:00
Raymond Hill
c7dc65fe33
Minor improvement to set-constant scriptlet
Disregard type matching for when the target property
is `null` or is set to `null`.
2020-01-21 10:57:55 -05:00
Raymond Hill
9367a6015b
Convert new setTimeout-if scriptlet to blacklist approach
As per feedback from filter list maintainers, the
whitelist approach has been deemed to confusing.

The scriptlet has been renamed `no-setTimeout-if`
alias `nostif` to reflect the blacklist approach.

`setInterval-if` has been Similarly changed to
`no-setInterval-if` alias `nosiif`.
2019-09-15 11:01:50 -04:00
Raymond Hill
2fd86a66fc
Add json-prune.js scriptlet
The scriptlet will trap calls to JSON.parse, and
if the result of the parsing is an Object, it
will remove specified properties from the result
before returning to the caller.

Usage:

    ##+js(json-prune, arg1, [arg2])

Where:

- arg1: a list of space-separated properties to remove

- arg2: optional, a list of space-separated properties
        which must be all present for the pruning to
        occur

Example:

    ##+js(json-prune, enabled, adpath config)

A property in a list of properties can be a chain
of properties, example: adpath.url.first
2019-09-09 14:06:23 -04:00
Raymond Hill
35854e4baf
Use more descriptive name for raf-if.js
Related feedback:
- 6831967f5f (commitcomment-34979880)
2019-09-06 09:40:04 -04:00
Raymond Hill
e3043fadc7
Fix console logging ability in setTimeout-if
Regression from e0fd9750d4
2019-08-25 09:38:08 -04:00
Raymond Hill
e0fd9750d4
Further fix new setTimeout-if/setInterval-if scriptlets
Addtionally, a dedicated test page has been added:

https://gorhill.github.io/uBlock/tests/scriptlet-injection-filters-1.html
2019-08-25 09:03:24 -04:00
Raymond Hill
e0f0aedad6
Ability to negate delay in new setTimeout-if scriptlet
This also apply to setInterval-if. Thus to defuse
calls to setTimeout(fn, 1000), the filter could be:

    ##+js(stif, , !1000)

Meaning "allow setTimeout if the delay is not 1000".
2019-08-24 13:54:31 -04:00
Raymond Hill
c5536577b2
Add two scriptlets: setTimeout-if and setInterval-if
Usage is similar to that of raf-if introduced in
commit 6831967f5f.

The two new scriptlets are meant to replace:
- setTimeout-defuser
- setTimeout-logger
- setInterval-defuser
- setInterval-logger

setTimeout-logger and setInterval-logger have been
removed, since they are not to be used in production.

To log setTimeout and setInterval usage, respectively
(using aliases):
- ##+js(stif)
- ##+js(siif)

To defuse setTimeout unconditionally:
- ##+js(stif, !)

Usage of setTimeout-defuser and setInterval-defuser
is deprecated and will be removed in some future when
they are no longer in use.

Keep in mind that the new scriptlets function on a
whitelist basis, whereas the deprecated ones
function on a blacklist basis. Prefixing the needle
with `!` allow to use the new scriptlets on a
blacklist basis.
2019-08-22 09:32:46 -04:00
Raymond Hill
252ce421c9
Fix raf-if scriptlet: bad Proxy target
It was working nonetheless, which made me
miss the mistake.
2019-08-21 10:36:08 -04:00
Raymond Hill
6831967f5f
Add new scriptlet to defuse calls to requestAnimationFrame
Scriptlet name: `raf-if.js`

Usage: `example.com##+js(raf-if, !/(\d+){4}/)`

Argument: one single argument, which is the "needle" to
find in the stringified argument passed to
requestAnimationFrame.

requestAnimationFrame will be defused when:

- The needle is not prefixed with `!` and the needle
  does not match the stringified argument; OR
- The needle is prefixed with `!` and the needle
  matches the stringified argument.

The `raf-if.js` scriptlet will log calls to
requestAnimationFrame to the console when no parameter
is provided, i.e.:

    example.com##+js(raf-if)

Otherwise no logging occurs.
2019-08-21 10:13:23 -04:00
Raymond Hill
3d66bdc8e9
Add shorthand alias for set-constant.js: set.js 2019-07-29 10:16:36 -04:00
Raymond Hill
a89aad0304
Remove trailing spaces
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/679
2019-07-22 07:32:39 -04:00
Raymond Hill
ce644c5960
Remove code unused in next release
Since https://github.com/uBlockOrigin/uBlock-issues/issues/156
won't be fixed in next release, no need to ship
with code which will be unused, and anyways only once
the fix is worked on will it be clear exactly what needs
to be used by scriptlets to deal harmoniously with
property listener collisions.
2019-07-11 10:17:06 -04:00