Skip to content

Commit

Permalink
AG-24597: support for $to in mv3 converter && updated dependencies fo…
Browse files Browse the repository at this point in the history
…r mv3 example

Merge in ADGUARD-FILTERS/tsurlfilter from feature/AG-24597 to master

Squashed commit of the following:

commit 0938724
Author: Dmitriy Seregin <d.seregin@adguard.com>
Date:   Mon Aug 7 20:02:20 2023 +0400

    AG-24597: support for $to in mv3 converter && updated dependencies for mv3 example
  • Loading branch information
105th committed Aug 8, 2023
1 parent 43db0f5 commit 3fa26b5
Show file tree
Hide file tree
Showing 11 changed files with 1,279 additions and 137 deletions.
14 changes: 12 additions & 2 deletions packages/examples/tswebextension-mv3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
"test": "rimraf tmp && cross-env PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS=1 node -r esbuild-register ./scripts/browser-test/index.ts"
},
"dependencies": {
"@adguard/tswebextension": "^0.1.2",
"@adguard/tswebextension": "^0.3.8",
"assert": "^2.0.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react-dom": "^17.0.2",
"stream-browserify": "^3.0.0",
"url": "^0.11.1",
"util": "^0.12.5"
},
"devDependencies": {
"@adguard/tsurlfilter": "^2.0.1",
Expand All @@ -29,6 +35,8 @@
"@babel/preset-typescript": "^7.16.0",
"@types/react": "^17.0.41",
"@types/react-dom": "^17.0.14",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"axios": "^0.26.0",
"babel-loader": "^8.2.3",
"chalk": "^5.0.1",
Expand All @@ -39,6 +47,8 @@
"esbuild": "^0.14.1",
"esbuild-register": "^3.2.0",
"eslint": "8.25.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-react": "^7.29.4",
"fs-extra": "^10.1.0",
"html-webpack-plugin": "^5.5.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs';
import { Configuration } from 'webpack';
import { Configuration, ProvidePlugin } from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
Expand Down Expand Up @@ -68,9 +68,12 @@ export const config: Configuration = {
resolve: {
extensions: ['*', '.tsx', '.ts', '.js'],
fallback: {
url: false,
path: false,
fs: false,
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
url: require.resolve('url'),
util: require.resolve('util'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
},
},
module: {
Expand All @@ -91,6 +94,12 @@ export const config: Configuration = {
},
plugins: [
new CleanWebpackPlugin(),
new ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new ProvidePlugin({
process: 'process/browser',
}),
new HtmlWebpackPlugin({
template: path.join(POPUP_PATH, 'index.html'),
filename: 'pages/popup.html',
Expand Down
1,058 changes: 1,011 additions & 47 deletions packages/examples/tswebextension-mv3/yarn.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion packages/tsurlfilter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- TODO: manually add compare links for version to the end of the file -->
<!-- e.g. [1.0.77]: https://github.com/AdguardTeam/tsurlfilter/compare/tsurlfilter-v1.0.76...tsurlfilter-v1.0.77 -->

## UNRELEASED

### Added
- Support for `$to` modifier in the MV3 converter.

## [2.1.6] - 2023-08-04

### Changed
Expand All @@ -24,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.1.4] - 2023-07-13

### Added
- Support for $csp modifier in the MV3 converter.
- Support for `$csp` modifier in the MV3 converter.
- Scheme for converting network rules into declarative rules.

### Changed
Expand Down
120 changes: 64 additions & 56 deletions packages/tsurlfilter/src/rules/declarative-converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -897,19 +897,7 @@ example 1
↓↓↓↓ converted to ↓↓↓↓

```json
[
{
"id": 1,
"action": {
"type": "block"
},
"condition": {
"urlFilter": "||evil.com^",
"isUrlFilterCaseSensitive": false
},
"priority": 76
}
]
[]

```
example 2
Expand All @@ -921,19 +909,7 @@ example 2
↓↓↓↓ converted to ↓↓↓↓

```json
[
{
"id": 1,
"action": {
"type": "block"
},
"condition": {
"urlFilter": "||evil.com^",
"isUrlFilterCaseSensitive": false
},
"priority": 2
}
]
[]

```
example 3
Expand All @@ -945,19 +921,7 @@ example 3
↓↓↓↓ converted to ↓↓↓↓

```json
[
{
"id": 1,
"action": {
"type": "allow"
},
"condition": {
"urlFilter": "||evil.com",
"isUrlFilterCaseSensitive": false
},
"priority": 100101
}
]
[]

```
example 4
Expand All @@ -969,19 +933,7 @@ example 4
↓↓↓↓ converted to ↓↓↓↓

```json
[
{
"id": 1,
"action": {
"type": "allow"
},
"condition": {
"urlFilter": "||evil.com",
"isUrlFilterCaseSensitive": false
},
"priority": 100002
}
]
[]

```
<a name="basic_modifiers__$popup"></a>
Expand Down Expand Up @@ -1064,7 +1016,7 @@ example 2
```
<a name="basic_modifiers__$to"></a>
## $to
<b>Status</b>: not implemented yet
<b>Status</b>: supported
<br/>
<b>Examples:</b>
<br/>
Expand All @@ -1085,7 +1037,25 @@ example 1
},
"condition": {
"urlFilter": "/ads",
"isUrlFilterCaseSensitive": false
"requestDomains": [
"evil.com",
"evil.org"
],
"isUrlFilterCaseSensitive": false,
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"media",
"websocket",
"other"
]
},
"priority": 2
}
Expand All @@ -1109,7 +1079,27 @@ example 2
},
"condition": {
"urlFilter": "/ads",
"isUrlFilterCaseSensitive": false
"requestDomains": [
"evil.com"
],
"excludedRequestDomains": [
"not.evil.com"
],
"isUrlFilterCaseSensitive": false,
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"media",
"websocket",
"other"
]
},
"priority": 2
}
Expand All @@ -1133,7 +1123,25 @@ example 3
},
"condition": {
"urlFilter": "/ads",
"isUrlFilterCaseSensitive": false
"excludedRequestDomains": [
"good.com",
"good.org"
],
"isUrlFilterCaseSensitive": false,
"resourceTypes": [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"font",
"object",
"xmlhttprequest",
"ping",
"media",
"websocket",
"other"
]
},
"priority": 2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,18 @@ export abstract class DeclarativeRuleConverter {
condition.excludedInitiatorDomains = this.toASCII(excludedDomains);
}

// set excludedRequestDomains
const permittedToDomains = rule.getPermittedToDomains();
if (permittedToDomains && permittedToDomains.length > 0) {
condition.requestDomains = this.toASCII(permittedToDomains);
}

// Can be specified $to or $denyallow, but not together.
const denyAllowDomains = rule.getDenyAllowDomains();
const restrictedToDomains = rule.getRestrictedToDomains();
if (denyAllowDomains && denyAllowDomains.length > 0) {
condition.excludedRequestDomains = this.toASCII(denyAllowDomains);
} else if (restrictedToDomains && restrictedToDomains.length > 0) {
condition.excludedRequestDomains = this.toASCII(restrictedToDomains);
}

// set excludedResourceTypes
Expand All @@ -468,9 +476,11 @@ export abstract class DeclarativeRuleConverter {
* other types, so that it works not only for document requests, but
* also for all other types of requests.
*/
const shouldMatchAllResourcesTypes = rule.isOptionEnabled(NetworkRuleOption.RemoveHeader)
|| rule.isOptionEnabled(NetworkRuleOption.Csp)
|| rule.isOptionEnabled(NetworkRuleOption.To);
const emptyResourceTypes = !condition.resourceTypes && !condition.excludedResourceTypes;
if ((rule.isOptionEnabled(NetworkRuleOption.RemoveHeader) || rule.isOptionEnabled(NetworkRuleOption.Csp))
&& emptyResourceTypes && !rule.isAllowlist()) {
if (shouldMatchAllResourcesTypes && emptyResourceTypes && !rule.isAllowlist()) {
condition.resourceTypes = [
ResourceType.MainFrame,
ResourceType.SubFrame,
Expand Down Expand Up @@ -683,7 +693,6 @@ export abstract class DeclarativeRuleConverter {
{ option: NetworkRuleOption.Stealth, name: '$stealth' },
/* Specific exceptions */
{ option: NetworkRuleOption.Method, name: '$method' },
{ option: NetworkRuleOption.To, name: '$to' },
{
option: NetworkRuleOption.Popup,
name: '$popup',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ page$domain=targetdomain.com|~example.org
||domain.com$~third-party

! ## $to
! <b>Status</b>: not implemented yet
! <b>Status</b>: supported
! <br/>
! <b>Examples:</b>
! <br/>
Expand Down Expand Up @@ -407,7 +407,7 @@ page$domain=targetdomain.com|~example.org
/some$domain=example.com|~example.org,badfilter

! ## $cookie
! <b>Status</b>: not implemented yet
! <b>Status</b>: implemented in `release/v2.2` branch
! <br/>
! <b>Examples:</b>
! <br/>
Expand Down
Loading

0 comments on commit 3fa26b5

Please sign in to comment.