Commit Graph

1553 Commits

Author SHA1 Message Date
Raymond Hill 60e254608a
Expose hasQuery() and fix coarse test for query parameters 2021-08-17 16:49:43 -04:00
Raymond Hill 8959cea3cc
Expose matchAndFetchModifiers() in npm package
Also, add instrumentation for the method in dig-snfe.
2021-08-17 12:48:39 -04:00
Manish Jethani a9aca818f9
Add tests for enableWASM() (#3835) 2021-08-17 09:53:28 -04:00
Manish Jethani 9a5a13a506
Add --full-battery option for tests (#3834) 2021-08-17 08:55:31 -04:00
Raymond Hill b44d9219c3
New revision for dev build 2021-08-17 08:25:31 -04:00
Manish Jethani 0bf19cc683
Run SNFE tests with Wasm off and on (#3833) 2021-08-17 08:24:07 -04:00
Manish Jethani f020e5334c
Use createWorld() in request data tests (#3832) 2021-08-17 07:20:13 -04:00
Raymond Hill f0cb4091f0
Bump up npm package version 2021-08-16 12:56:39 -04:00
Raymond Hill be7418264b
Exclude more resources from the published npm package 2021-08-16 12:40:46 -04:00
Raymond Hill 10ca7438d7
Increase the logging of first best/worst requests to 1000 2021-08-16 10:54:27 -04:00
Manish Jethani ffb4fe9b8f
Run request data tests with Wasm enabled too (#3829) 2021-08-16 09:22:35 -04:00
Manish Jethani 36377320ae
Run tests on request data (#3828) 2021-08-16 07:39:09 -04:00
Manish Jethani 514143cd80
Add c8 (#3826) 2021-08-15 17:33:56 -04:00
Manish Jethani e009d69f86
Add tests for SNFE deserialization (#3827) 2021-08-15 17:28:16 -04:00
Raymond Hill 8bb44242bd
Add platform "dig", to experiment/validate code changes
This is a replacement for the dubious approach when the
extension itself was used to run benchmarks to detect
performance and filtering behavior regressions.
2021-08-15 15:47:40 -04:00
Manish Jethani 29cea49197
Add tests for SNFE serialization (#3825) 2021-08-15 11:49:23 -04:00
Raymond Hill 0ec1204d37
Merge branch 'master' of https://github.com/gorhill/uBlock 2021-08-15 11:19:35 -04:00
Raymond Hill e9ae8e1a0f
Add static release() to StaticNetFilteringEngine class
The method ensures the actual SNFE is properly reset.
2021-08-15 11:18:01 -04:00
Manish Jethani 48d4f890d7
Add tests for SNFE initialization (#3823) 2021-08-15 11:16:57 -04:00
Manish Jethani f8f45cab70
Lint Mocha tests too (#3824) 2021-08-15 11:13:13 -04:00
Raymond Hill 087da6407d
Add support for nodejs flavors
The main nodejs flavor is "npm", which is to be used to
lint/test and the publication of an official npm
package -- and by design it has dependencies on mocha,
eslint, etc.

A new flavor "dig" has been created with minimal
dependencies and which purpose is to easily allow to
write specialized code to investigate local code changes
in uBO -- and it's not meant for publication.

Consequently, "make nodejs" has been replaced with
"make npm", and a new "dig" target has been added to the
makefile, to be used for instrumenting local code changes
for investigation purpose.
2021-08-15 10:43:36 -04:00
Manish Jethani 0a11999459
Test in new world (#3822) 2021-08-15 08:41:30 -04:00
Manish Jethani 6c2856cb7e
Add package-lock.json (#3819) 2021-08-14 11:59:14 -04:00
Manish Jethani fd9888f85e
Spawn mocha from test.js (#3818) 2021-08-14 10:33:49 -04:00
Manish Jethani bb5bfed779
Add tests for promise-based filter loading (#3817) 2021-08-14 07:56:03 -04:00
Manish Jethani ef0075acc1
Add tests for filter loading (#3816) 2021-08-13 16:21:36 -04:00
Manish Jethani 806fe5dbe1
Add Mocha tests (#3815) 2021-08-13 13:08:13 -04:00
Manish Jethani a56f43f007
Add .npmrc to stop generating package lock file (#3814) 2021-08-13 11:49:52 -04:00
Manish Jethani daff6b3a34
Add eslint dependency within Node.js package (#3813) 2021-08-13 06:43:20 -04:00
Manish Jethani 993835b333
Use test assertions (#3811) 2021-08-10 14:08:05 -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
Manish Jethani ab9f5ae100
Run build script via tools/make-nodejs.sh (#3808) 2021-08-09 20:02:58 -04:00
Raymond Hill 76abd04898
New revision for npm package 2021-08-09 19:34:35 -04:00
Manish Jethani 6b993f2f06
Fix pslInit() for install script (#3807) 2021-08-09 19:12:04 -04:00
Manish Jethani d9adf5a6fb
Add serialization API to StaticNetFilteringEngine (#3806) 2021-08-09 16:52:41 -04:00
Raymond Hill 19f59df22d
Increase minimum version to Firefox 60.0
JavaScript modules becames officially available in
Firefox 60.0, which was published more than 3 years
ago.
2021-08-08 10:47:04 -04:00
Raymond Hill 5879610597
Bump up nodejs package version 2021-08-08 09:21:03 -04:00
Raymond Hill 7cd583a301
Revisit the nodejs API 2021-08-08 09:17:14 -04:00
Manish Jethani 65f0909ba0
Implement class StaticNetFilteringEngine (#3805) 2021-08-08 07:22:02 -04:00
Raymond Hill 500c895f6b
update npm README 2021-08-07 11:38:22 -04:00
Raymond Hill af54415959
README has unsaved pending edits... 2021-08-06 08:29:13 -04:00
Raymond Hill 4495c37ca3
Provide basic documentation for the NPM package 2021-08-06 08:25:36 -04:00
Raymond Hill 5eb99a4dd6
... 2021-08-05 14:36:13 -04:00
Raymond Hill 05f0e04c07
Just trying to get this done.. 2021-08-05 14:34:21 -04:00
Raymond Hill fe7ce8f576
Need to bump version to publish README 2021-08-05 14:32:07 -04:00
Raymond Hill 70d5d28a7c
Add minimal README to nodejs package 2021-08-05 14:28:17 -04:00
Raymond Hill 8c48375caf
Fix test.js following changes in API 2021-08-05 14:19:04 -04:00
Raymond Hill 63e55a1696
Expose ability to compile raw list into their intermeditate form
For clients who may wish to persist the intermediate compiled form
in order to be able to skip costly parsing operation when the
list is fed to the static network filtering engine.
2021-08-05 13:37:41 -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
Manish Jethani 543e1a3aea
Add ESLint rules for possible errors (#3804) 2021-08-04 15:27:32 -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 cbec7397fc
Fix jshint warnings
Those warnings surfaced as a result of removing the braces
used to create a local namespace.
2021-08-03 12:08:59 -04:00
Manish Jethani 4094f48547
Fix style in index.js (#3802) 2021-08-03 12:03:11 -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 6b85b7f2b1
Create build folder in npm install script (#3799) 2021-08-03 07:02:48 -04:00
Manish Jethani ad69c760fb
Run ESLint during Node.js package generation (#3798) 2021-08-02 16:55:03 -04:00
Manish Jethani 502e5b0ec8
Use fs API to load serialized PSL (#3797) 2021-08-02 12:32:47 -04:00
Manish Jethani 3879835324
Remove bundle generation from Node.js package (#3796) 2021-08-02 09:17:56 -04:00
Raymond Hill f1106acf4b
Rename nodejs package
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-890834827
2021-08-02 08:08:43 -04:00
Manish Jethani 297bcea49b
Generate bundle.min.js in Node.js install script (#3794) 2021-08-01 18:33:13 -04:00
Manish Jethani 0b764934e0
Serialize PSL in Node.js install script (#3793) 2021-08-01 16:42:05 -04:00
Raymond Hill c6d275674d
Revert "Make the nodejs package load a serialized version of the PSL"
This reverts commit 46c6ff8708.
2021-08-01 15:42:46 -04:00
Raymond Hill 46c6ff8708
Make the nodejs package load a serialized version of the PSL
Related discussion:
- https://github.com/cliqz-oss/adblocker/pull/2091#issuecomment-890545926
2021-08-01 12:58:21 -04:00
Manish Jethani 8a33bda653
Use lower case for Node.js package name (#3792) 2021-08-01 05:22:57 -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 2eb02c5adc
Fix spurious error message in dev console
Ports can be disconnected under certain conditions,
and in such case runtime.lastError must be accessed
to avoid the extensions framework from emitting
error messages in the console.
2021-07-31 07:20:38 -04:00
Raymond Hill 23cabfd440
Fix erroneous removal of code from pslInit() 2021-07-31 07:09:01 -04:00
Raymond Hill d5da88ea87
Simplify loading of WASM modules in nodejs 2021-07-31 07:06:11 -04:00
Raymond Hill 5be4d5d877
Make pslInit() returns the publicSuffixList instance used internally
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-889647595
2021-07-30 07:00:45 -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 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 e1222d1643
Use `require` instead of `fs`
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-888332409
2021-07-28 10:38:24 -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 c9710ac9d1
Better deal with no-longer-existing ports
Disconnected ports could still happen Even when the port
was still seen as valid internally. Using a try-catch
block makes invalid port detection more reliable. This
is an occurrence I often encountered when stepping into
content script code, causing suprious error messages to
be thrown into uBO's background dev console.
2021-07-19 11:25:52 -04:00
Raymond Hill e3f8a612f4
Minor code review 2021-07-16 14:06:59 -04:00
Raymond Hill bad1506f20
Move chromium-specific code path to chromium directory 2021-07-16 10:29:39 -04:00
Raymond Hill a4aced69dc
Reorganize platform directory to avoid Chromium-centric appearance
Though Firefox shares a lot of WebExtensions code with Chromium,
these platforms have their own specific code paths, for various
reasons.

The reorganization here makes it clear that Chromium platform is
just one flavor of WebExtensions, and as such all Chromium-specific
code paths should no longer be automatically pulled by other
platforms where these code paths are not needed.

Given that the filepath of many files changed, here is the
parent commit to quickly browse back to the previous directory
layout:

ec7db30b2f
2021-07-16 10:06:58 -04:00
Raymond Hill d17e22a505
Fix spurious error messages when updating contextual menu
There were spurious error messages in the dev console of
uBO in Firefox, because Firefox does not silently ignore
duplicate contextual menu entries, which could occur
transiently when the contextual menu entries were updated.

The fix simplifies contextual menu code, and actually
fulfill the original goal of avoiding to call extensions
framework API as much as possible.
2021-07-15 13:14:37 -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
Raymond Hill a1241e0806
Don't use `self` to access `vAPI` in content script
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1571

Testing through `self` breaks the injection of
`contentscript-extra.js` in Firefox 66.0 and
earlier.
2021-04-29 13:04:59 -04:00
Raymond Hill 1c3b45f75d
Expose ability to toggle on/off cname-uncloaking to all users
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1513

Prior to this commit, the ability to enable/disable the
uncloaking of canonical names was only available to advanced
users. This commit make it so that the setting can be
toggled from the _Settings_ pane.

The setting is enabled by default. The documentation should
be clear that the setting should not be disabled unless it
actually solves serious network issues, for example:

https://bugzilla.mozilla.org/show_bug.cgi?id=1694404

Also, as a result, the advanced setting `cnameUncloak` is no
longer available from within the advanced settings editor.
2021-03-02 13:00:56 -05:00
Raymond Hill 6eb1246508
Add `userSettings` entry to managed storage
The managed `userSettings` entry is an array of entries,
where each entry is a name/value pair encoded into an array
of strings.

The first item in the entry array is the name of a setting,
and the second item is the stringified value for the
setting.

This is a more convenient way for administrators to set
specific user settings. The settings set through
`userSettings` policy will always be set at uBO launch
time.
2021-01-16 10:35:56 -05:00
Raymond Hill 649b3480e0
Add "toOverwrite.filters" entry as managed storage property
The new entry is an array of strings, each representing a
distinct line, and all entries are used to populate the
"My filters" pane.

This offers an more straightforward way for administrators
to specify a list of custom filters to use for all
installations.
2021-01-10 12:31:31 -05:00
Raymond Hill ecabc6d12c
Raise minimal version numbers 2021-01-10 12:14:07 -05:00
Raymond Hill 0e3071dd50
Add `filterLists` property to managed storage
The entry `toOverwrite.filterLists` is an array of
string, where each string is a token identifying a
stock filter list, or a URL for an external filter
list.

This new entry is to make it easier for an
administrator to centrally configure uBO with a
custom set of filter lists.
2021-01-08 09:18:26 -05:00
Raymond Hill cc9c45f1e4
Adding to and further reviewing admin-managed settings 2021-01-06 11:39:24 -05:00
Raymond Hill 5f323f270e
Remove stray comma 2021-01-05 15:58:55 -05:00
Raymond Hill c1130ec843
Add support for admin-managed hidden settings
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1437#issuecomment-754127066
2021-01-05 12:16:50 -05:00
Raymond Hill b28acfccbc
Add "extraTrustedSiteDirectives" as new admin policy
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1433

The new "extraTrustedSiteDirectives" policy is an array
of strings, each of which is parsed as a trusted-site
directive to append to a user's own set of trusted-site
directives at launch time.

The added trusted-site directives will be considered as
part of the default set of directives by uBO.
2021-01-04 07:54:24 -05:00
Raymond Hill db7f54dbf6
Add support to launch element picker in embedded frames
Related issue:
- https://github.com/gorhill/uBlock/issues/1744

A new context menu entry, "Block element in frame...", will
be present when right-clicking on a frame element. When
this entry is clicked, uBO's element picker will be
launched from within the embedded frame and function the
same way as when launched from within the page.
2020-12-05 15:26:29 -05:00
Raymond Hill f8b15ed6cc
Fix calls to tab.removeCSS()
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1375
2020-12-02 10:46:59 -05:00
Raymond Hill 4d68d7f586
Fix handling of no-longer-existing port condition
The condition has been spotted occurring when bringing
up the DOM inspector for a page on which cosmetic filters
are being applied.

Not clear why this happens, but uBO must be ready to
graciously handle such condition.
2020-12-02 10:07:14 -05:00
Raymond Hill 525d7b1b3b
Fine tune port connection code
Related commit:
- a223031b98
2020-11-13 08:32:51 -05:00
Raymond Hill a223031b98
Work around Firefox's `data:` favIconUrl leak
Related issue:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1652925
2020-11-12 12:14:59 -05:00
Raymond Hill 8985376b00
Fix timing issue with cached redirection to web accessible resources
Reported internally by @gwarser.

In rare occasion, a timing issue could cause uBO to redirect
to a web accessible resource meant to be used for another
network request. This is a regression introduced with the
following commit:

- 2e5d32e967

Additionally, I identified another issue which would cause
cached redirection to fail when a cache entry with redirection
to a web accessible resource was being reused, an issue which
could especially affect pages which are generated dynamically
(i.e. without full page reload).
2020-11-10 10:43:26 -05:00
Raymond Hill 1e2eb037e5
Add new filter option `queryprune=`
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/760

The purpose of this new network filter option is to remove
query parameters form the URL of network requests.

The name `queryprune` has been picked over `querystrip`
since the purpose of the option is to remove some
parameters from the URL rather than all parameters.

`queryprune` is a modifier option (like `csp`) in that it
does not cause a network request to be blocked but rather
modified before being emitted.

`queryprune` must be assigned a value, which value will
determine which parameters from a query string will be
removed. The syntax for the value is that of regular
expression *except* for the following rules:

- do not wrap the regex directive between `/`
- do not use regex special values `^` and `$`
- do not use literal comma character in the value,
  though you can use hex-encoded version, `\x2c`
- to match the start of a query parameter, prepend `|`
- to match the end of a query parameter, append `|`

`queryprune` regex-like values will be tested against each
key-value parameter pair as `[key]=[value]` string. This
way you can prune according to either the key, the value,
or both.

This commit introduces the concept of modifier filter
options, which as of now are:

- `csp=`
- `queryprune=`

They both work in similar way when used with `important`
option or when used in exception filters. Modifier
options can apply to any network requests, hence the
logger reports the type of the network requests, and no
longer use the modifier as the type, i.e. `csp` filters
are no longer reported as requests of type `csp`.

Though modifier options can apply to any network requests,
for the time being the `csp=` modifier option still apply
only to top or embedded (frame) documents, just as before.
In some future we may want to apply `csp=` directives to
network requests of type script, to control the behavior
of service workers for example.

A new built-in filter expression has been added to the
logger: "modified", which allow to see all the network
requests which were modified before being emitted. The
translation work for this new option will be available
in a future commit.
2020-10-31 10:42:53 -04:00
Raymond Hill 3059db77c4
Use proxy detection code path only on Firefox 79 and less
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/911

This was fixed in Firefox 80:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1618271
2020-10-14 13:37:09 -04:00
Raymond Hill 03596439ca
Remove obsolete code to import content of localStorage
Months ago, usage of synchronous localStorage was replaced
with asynchronous extension storage. There was code for the
conversion to be seamless by importing the content of now
obsolete localStorage.

This code is no longer needed as majority of users are
assumed to use versions of uBO above 1.25.0.

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/899
2020-10-10 14:18:19 -04:00