1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-29 14:17:11 +02:00
Commit Graph

2421 Commits

Author SHA1 Message Date
Raymond Hill
f0b46bde4f
Mitigate generic cosmetic filters erroneously targeting html/body
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1692

The ids/classes from html/body elements will leave out
looking up lowly generic cosmetic filters made of a single
identifier.

This does not absolutely guarantee that html/body elements
will never be targeted, but it should greatly mitigate the
probability that this erroneously happens.
2021-08-24 10:03:25 -04:00
Manish Jethani
925c01dc14
Fix ESLint globals error in biditrie.js (#3850) 2021-08-23 11:10:49 -04:00
Manish Jethani
d959c7aabe
Remove globals.js (#3849) 2021-08-23 10:54:16 -04:00
Manish Jethani
d13294dd39
Remove globals usage from background.js (#3848) 2021-08-23 10:28:44 -04:00
Manish Jethani
724a946c79
Remove globals usage from start.js (#3847) 2021-08-23 10:16:02 -04:00
Manish Jethani
9761b02c79
Convert publicsuffixlist.js into an ES module (#3846) 2021-08-23 09:42:27 -04:00
Raymond Hill
ba83c21354
Fix trie instance iterator 2021-08-22 13:06:05 -04:00
Manish Jethani
9ddbb293c0
Convert punycode.js into an ES module (#3845) 2021-08-22 12:03:59 -04:00
Manish Jethani
1bde1e5ecb
Convert regex.js into an ES module (#3844) 2021-08-22 08:25:06 -04:00
Raymond Hill
9d4006f2c3
Include query string when evaluating matches-path()
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1690#issuecomment-903133439
2021-08-21 11:50:46 -04:00
Raymond Hill
c0c70e2987
Fix normalization of matches-path operator
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1690
2021-08-21 10:20:43 -04:00
Raymond Hill
9dece3bd30
Add new procedural cosmetic operator: :matches-path(...)
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1690

New procedural operator: `:matches-path(...)`

Description: this is a all-or-nothing passthrough operator, which
on/off behavior is dictated by whether the argument match the
path of the current location. The argument can be either plain
text to be found at any position in the path, or a literal regex
against which the path is tested.

Whereas cosmetic filters can be made specific to whole domain,
the new `:matches-path()` operator allows to further narrow
the specificity according to the path of the current document
lcoation.

Typically this procedural operator is used as first operator in
a procedural cosmetic filter, so as to ensure that no further
matching work is performed should there be no match against the
current path of the current document location.

Example of usage:

    example.com##:matches-path(/shop) p

Will hide all `p` elements when visiting `https://example.com/shop/stuff`,
but not when visiting `https://example.com/` or any other page
on `example.com` which has no instance of `/shop` in the path part
of the URL.
2021-08-21 09:41:48 -04:00
Manish Jethani
5d2c295600
Remove globals usage from hntrie.js (#3842) 2021-08-21 07:33:53 -04:00
Manish Jethani
ab13903019
Remove globals usage from static-net-filtering.js (#3841) 2021-08-20 07:54:05 -04:00
Raymond Hill
19160f9018
Drop requestIdleCallback from globals
Related discussion:
- https://github.com/gorhill/uBlock/pull/3839

`requestIdleCallback` can be assumed always present on
browser-related platforms.
2021-08-19 07:31:27 -04:00
Raymond Hill
68675ed1cd
Remove pointless dependency on location
Related discussion:
- https://github.com/gorhill/uBlock/pull/3839#discussion_r691502793
2021-08-19 07:23:53 -04:00
Manish Jethani
b19393d8dc
Add tasks.js module (#3839) 2021-08-19 07:19:20 -04:00
Raymond Hill
9ceef65f9a
Fix regression with reporting "important" in logger
Related feedback:
- a2a8ef7e85 (commitcomment-54972030)
2021-08-17 07:32:54 -04:00
Raymond Hill
a33f70cf20
Provide compiler/selfie versions for snfe
So as to allow nodejs usage to better deal with
out of date serialization/compilation.

Additionally, use FilterImportant() only when a
"block-important" filter is stored in the "block" realm.
2021-08-16 12:15:30 -04:00
Raymond Hill
a2a8ef7e85
Avoid matching the block-important realm unconditionally
When matching a network request in the static network filtering
engine ("snfe"), these are the possible outcomes, from most
to least likely:

- No block
- Block
- Unblock ("exception" filter overriding the block)
- Block-important ("important" filter override the unblock)

Hence why the matching in the snfe always check for a match in
the "block" realm, and the "unblock" realm would be checked
if and only if there was a match in the "block" realm.

However the "block-important" realm was always matched against
first, and when a match in that realm was found, there would
be no need to check in other realms since nothing can override
the "important" option. The problem with this approach though
is that matches in the "block-important" realm are most
unlikely, which means pointless work being done for vast
majority of network requests.

This commit makes it so that the "block-important" realm is
matched against ONLY when there is a matched "unblock" filter.
The result is a measurable improvement in the snfe-related
benchmarks (though given the numbers involved, end users won't
perceive a difference).

Somewhat related discussion which was the motivation to look
more into this:

https://github.com/cliqz-oss/adblocker/discussions/2170#discussioncomment-1168125
2021-08-16 10:58:04 -04:00
Raymond Hill
c6fb70b1f0
Refactor hntrie to avoid the need for boundary cells
Whereas before the string segment was encoded as:

LL OOOOOOOOOOOO

where L are the upper 8 bits and used to encode the length
of the segment, and O are the lower 24 bits and used to
encode the offset of the string data in the character
buffer, the new code encode as follow:

OOOOOOOOOOOO LL

And furthermore the most significant bit of the length
LL is now used to mark whether the current string segment
is a label boundary.

This means a cell can't reference a segment longer then
127 characters. To work around this limitation for when a
segment is longer than 127 characters (a rare occurrence),
the algorithm will simply split the segment into multiple
adjacent cells.

As a result, there is no longer a need to encode
"boundariness" into special cells, which simplifies
both the storing and matching algorithms.

Additionally, added minimal documentation for the NPM
package on how to import and use HNTrieContainer as a
standalone API.
2021-08-10 09:27:59 -04:00
Raymond Hill
b54bf554a8
Fix bad test in WASM version of HNTrieContainer
The erroneous test does not seem to interfere
with the proper functioning of the trie, due
to the fact that nodes are never split without
a OR node or boundary node being present.

The issue was found when undertaking a rewrite
of the algorithm to avoid having to create
boundary nodes.
2021-08-09 07:02:00 -04:00
Raymond Hill
385acd7b0a
Fix eslint error 2021-08-08 11:49:31 -04:00
Raymond Hill
22768ddcd0
Remove undue dependencies on vAPI
Whether WebAssembly can be enabled or not should be
decided at a higher level.
2021-08-08 11:41:05 -04:00
Raymond Hill
7cd583a301
Revisit the nodejs API 2021-08-08 09:17:14 -04:00
Raymond Hill
4818405cf6
Remove need to pass parser at every compile() call
The compiler instance is already initialized with a
reference to the parser, no need to keep passing the
reference at each call to compile().
2021-08-05 13:30:20 -04:00
Raymond Hill
85c68116bd
Group all compiling-related code into FilterCompiler() class
In the static network filtering engine (snfe), the
compiling-related code was spread across two classes.
This commit makes it so that all the compiling-related
code is in FilterCompiler class, which clear purpose is
to compile raw filters into a form which can be persisted
and later fed to the snfe with no parsing overhead.

To compile raw static network filter, the new approach is:

    snfe.createCompiler(parser);

Then for each single raw filter to compile:

    compiler.compile(parser, writer);

The caller is responsible to keep a reference to the
compiler instance for as long as it is needed. This removes
the need for the clunky code used to keep an instance of
compiler alive in the snfe.

Additionally, snfe.tokenHistograms() has been moved to
benchmarks.js, as it has no dependency on the snfe, it's
just a utility function.
2021-08-04 15:14:48 -04:00
Raymond Hill
5e8f847aeb
Fix regression in cloud storage upload/download
Reported in team discussion

Regression from:
- 22022f636f
2021-08-03 14:03:00 -04:00
Raymond Hill
89c5653bc6
Export the rule-based filtering engines to the nodejs package
The code exported to nodejs package was revised to use modern
JavaScript syntax. A few issues were fixed at the same time.

The exported classes are:
- DynamicHostRuleFiltering
- DynamicURLRuleFiltering
- DynamicSwitchRuleFiltering

These related to the content the of "My rules" pane in the
uBlock Origin extension.
2021-08-03 12:19:25 -04:00
Manish Jethani
6ef74fc21b
Rewrite logical expressions for ESLint (#3801) 2021-08-03 10:59:01 -04:00
Manish Jethani
3ca5e6817d
Fix ESLint indentation warnings (#3800)
* Fix ESLint indentation warnings

* Undo code reformatting within parentheses

* Add exception for logical expressions

* Update array expression rule

* Disable rule for reProceduralOperator assignment

* Fix indentation in static-filtering-parser.js
2021-08-03 10:14:40 -04:00
Manish Jethani
ad69c760fb
Run ESLint during Node.js package generation (#3798) 2021-08-02 16:55:03 -04:00
Raymond Hill
f8daea085b
Remove assets dependency from redirect engine
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664

This change allows to add the redirect engine into the
nodejs package. The purpose of the redirect engine is to
resolve a redirect token into a path to a local resource,
to be used by the caller as wished.
2021-08-02 09:23:48 -04:00
vt
2b9aba2748 Handle invalid meta refresh URLs in noscript scriptlet
Invalid URLs like "http://" and "http://foo@" trigger TypeErrors
when they are passed to the URL constructor. These TypeErrors
caused the scriptlet to stop processing subsequent noscript nodes
due to uncaught exceptions.

These exceptions are now caught to allow all noscript nodes to
be processed.
2021-07-31 13:16:33 -04:00
Raymond Hill
cb72211795
Move orphanizeString() into text-utils module
Another small step toward the goal of reducing dependency
on `µb`.

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

text-iterators module has been renamed text-utils to better
reflect its content.
2021-07-31 08:38:33 -04:00
Raymond Hill
dc08478130
Fix https://github.com/uBlockOrigin/uBlock-issues/issues/1675 2021-07-31 07:15:19 -04:00
Raymond Hill
076a088371
Remove stray async 2021-07-29 17:04:32 -04:00
Raymond Hill
98fc66bb1b
Add support for enabling WASM code paths in NodeJS package
See `test.js` for reference on how to enable WASM code
paths (which are disabled by default).
2021-07-29 16:54:51 -04:00
Raymond Hill
8ef8c5ab2e
Group all benchmarking functions in a separate file
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664

The various filtering engine benchmarking functions are best
isolated in their own file since they have specific
dependencies that should not be suffered by the filtering
engines.

Additionally, moved decomposeHostname() into uri-utils.js
as it's a hostname-related function required by many
filtering engine cores -- this allows to further reduce
or outright remove dependency on `µb`.
2021-07-29 08:44:15 -04:00
Raymond Hill
62b6826dd5
Further modularize uBO's codebase
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664

Modularization is a necessary step toward possibly publishing
a more complete nodejs package to allow using uBO's filtering
capabilities outside of the uBO extension.

Additionally, as per feedback, remove undue usage of console
output as per feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-888451032
2021-07-28 19:48:38 -04:00
Raymond Hill
22022f636f
Modularize codebase with export/import
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664

The changes are enough to fulfill the related issue.

A new platform has been added in order to allow for building
a NodeJS package. From the root of the project:

    ./tools/make-nodejs

This will create new uBlock0.nodejs directory in the
./dist/build directory, which is a valid NodeJS package.

From the root of the package, you can try:

    node test

This will instantiate a static network filtering engine,
populated by easylist and easyprivacy, which can be used
to match network requests by filling the appropriate
filtering context object.

The test.js file contains code which is typical example
of usage of the package.

Limitations: the NodeJS package can't execute the WASM
versions of the code since the WASM module requires the
use of fetch(), which is not available in NodeJS.

This is a first pass at modularizing the codebase, and
while at it a number of opportunistic small rewrites
have also been made.

This commit requires the minimum supported version for
Chromium and Firefox be raised to 61 and 60 respectively.
2021-07-27 17:26:04 -04:00
Raymond Hill
89064478dd
Modernize code: URLSearchParams() API support is now widespread 2021-07-25 07:08:03 -04:00
Raymond Hill
c25938f5bc
Ensure compiled sections are ordered in ascending id
Related issue:
- https://www.reddit.com/r/uBlockOrigin/comments/oq6kt5/ubo_loads_generic_filter_instead_of_specific/h6a4nca/
2021-07-24 07:44:26 -04:00
Raymond Hill
51d14de44a
Fix handling of some procedural cosmetic filters with explicit :scope
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1011#issuecomment-884806241
2021-07-23 10:11:07 -04:00
Raymond Hill
cd237ed3e1
Fix rendering of punycoded hostname in popup panel
Regression from:
- 75deadd31e
2021-07-20 11:22:33 -04:00
Raymond Hill
75deadd31e
Provide visual cue in popup panel when base domain has subdomains
Related issue:
- https://github.com/gorhill/uBlock/issues/284
2021-07-20 08:37:05 -04:00
Raymond Hill
e85c6f2d3e
Merge background changes to user filters in "My filters" pane
Related issue:
- https://github.com/gorhill/uBlock/issues/3704
2021-07-17 12:03:56 -04:00
Raymond Hill
e3f8a612f4
Minor code review 2021-07-16 14:06:59 -04:00
Raymond Hill
ec7db30b2f
Simplify fetching title of tabs
The title of tabs in uBO is solely to have a better
presentation in the logger -- no other purpose.

This commit simplify keeping track of the titles, from
an active approach by directly querying it from tabs
whenever a change occurs, to a passive approach by
storing it when the title string become available in
some tab event handlers.
2021-07-16 08:59:30 -04:00
Raymond Hill
bbdb68a2b6
Synthesize missing expected onCreatedNavigationTarget events
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1659

This commit introduces a workaround for missing
onCreatedNavigationTarget() in Chromium.
2021-07-15 11:34:37 -04:00