Skip to content

Commit

Permalink
add settings.debugScriptlets. AG-27413
Browse files Browse the repository at this point in the history
AdguardTeam/AdguardBrowserExtension#2584

Squashed commit of the following:

commit d32feec
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 30 12:55:45 2023 +0200

    no extra settings.debugScriptlets checking

commit d5871d3
Author: Vladimir Zhelvis <v.zhelvis@adguard.com>
Date:   Thu Nov 30 13:46:22 2023 +0300

    add default value for debugScriptlets by zod

commit b949ebe
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 29 19:54:17 2023 +0200

    fix changelog

commit 12ca926
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 29 14:26:14 2023 +0200

    fix examples packages

commit 8690c50
Merge: 4a92c61 8d02bf8
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 29 14:24:56 2023 +0200

    merge master into the branch, resolve conflicts

commit 4a92c61
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Tue Nov 28 12:26:34 2023 +0200

    fix readme

commit 42a8fb9
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Tue Nov 28 12:25:15 2023 +0200

    update changelog

commit f9a2348
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Mon Nov 27 15:36:49 2023 +0200

    fix naming

commit cc32398
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Nov 24 13:23:11 2023 +0200

    fix changelog

commit 24a8bda
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Nov 24 13:16:34 2023 +0200

    add settings.verboseScriptletsLogging

commit 229e6b5
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Nov 24 13:15:35 2023 +0200

    update examples
  • Loading branch information
slavaleleka committed Nov 30, 2023
1 parent 8d02bf8 commit 3d6c256
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 12 deletions.
Expand Up @@ -29,6 +29,7 @@ const defaultConfig: ConfigurationMV2 = {
filteringEnabled: true,
stealthModeEnabled: true,
collectStats: true,
debugScriptlets: false,
allowlistInverted: false,
allowlistEnabled: false,
documentBlockingPageUrl: browser.runtime.getURL('pages/document-blocking.html'),
Expand Down
1 change: 1 addition & 0 deletions packages/examples/tswebextension-mv2/scripts/constants.ts
Expand Up @@ -30,6 +30,7 @@ export const DEFAULT_EXTENSION_CONFIG: ConfigurationMV2 = {
settings: {
assistantUrl: `${BuildOutput.AssistantInject}.js`,
collectStats: true,
debugScriptlets: false,
allowlistInverted: false,
allowlistEnabled: false,
stealthModeEnabled: true,
Expand Down
1 change: 1 addition & 0 deletions packages/examples/tswebextension-mv3/scripts/constants.ts
Expand Up @@ -18,6 +18,7 @@ export const DEFAULT_EXTENSION_CONFIG: Configuration = {
settings: {
assistantUrl: '',
collectStats: true,
debugScriptlets: false,
allowlistEnabled: true,
allowlistInverted: false,
stealthModeEnabled: true,
Expand Down
10 changes: 8 additions & 2 deletions packages/tswebextension/CHANGELOG.md
Expand Up @@ -8,11 +8,17 @@ 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. [0.1.2]: https://github.com/AdguardTeam/tsurlfilter/compare/tswebextension-v0.1.1...tswebextension-v0.1.2 -->

## [Unreleased]

### Added
- API `settings.debugScriptlets` property and `setDebugScriptlets()` method for its setting
[#2584](https://github.com/AdguardTeam/AdguardBrowserExtension/issues/2584).


## [0.4.8] - 2023-11-29

### Changed

- `MessageHandlerMV2` type is exported now.
- `MessageHandlerMV2` type is exported now.


## [0.4.7] - 2023-11-21
Expand Down
31 changes: 24 additions & 7 deletions packages/tswebextension/README.md
Expand Up @@ -24,11 +24,12 @@ Table of content:
- [allowlist](#allowlist)
- [trustedDomains](#trusteddomains)
- [userrules](#userrules)
- [verbose](#verbose)
- [verbose (deprecated)](#verbose)
- [settings](#settings)
- [allowlistInverted](#allowlistinverted)
- [allowlistEnabled](#allowlistenabled)
- [collectStats](#collectstats)
- [debugScriptlets](#debugscriptlets)
- [stealthModeEnabled](#stealthmodeenabled)
- [filteringEnabled](#filteringenabled)
- [documentBlockingPageUrl](#documentblockingpageurl)
Expand Down Expand Up @@ -58,6 +59,7 @@ Table of content:
- [getMessageHandler()](#getmessagehandler)
- [setFilteringEnabled() (MV2 only)](#setfilteringenabled-mv2-only)
- [setCollectHitStats() (MV2 only)](#setcollecthitstats-mv2-only)
- [setDebugScriptlets() (MV2 only)](#setdebugscriptlets-mv2-only)
- [setStealthModeEnabled() (MV2 only)](#setstealthmodeenabled-mv2-only)
- [setSelfDestructFirstPartyCookies() (MV2 only)](#setselfdestructfirstpartycookies-mv2-only)
- [setSelfDestructThirdPartyCookies() (MV2 only)](#setselfdestructthirdpartycookies-mv2-only)
Expand Down Expand Up @@ -155,7 +157,7 @@ Commands:

## API

The main idea of the library is to provide a common interface for different browsers and manifest versions.
The main idea of the library is to provide a common interface for different browsers and manifest versions.
via [Configuration](#configuration) object.

[TsWebExtension](#tswebextension-1) class provides a set of methods for filtering content from the extension's background context.
Expand Down Expand Up @@ -226,7 +228,7 @@ Path to the filter list file.

type: `string`

Path to directory with converted rule sets.
Path to directory with converted rule sets.

#### filteringLogEnabled (MV3 only)

Expand All @@ -252,7 +254,7 @@ type: `string[]`

List of rules added by user.

#### verbose (deprecated)
#### <a name="verbose"></a> verbose (deprecated)

type: `boolean | undefined`

Expand Down Expand Up @@ -288,6 +290,12 @@ type: `boolean`

Enables css hits counter if true.

##### debugScriptlets

Optional, type: `boolean`

Defaults to false. Enables scriptlets logging in console if true.

##### stealthModeEnabled

type: `boolean`
Expand Down Expand Up @@ -464,6 +472,15 @@ Updates [collectStats](#collectstats) configuration value without re-initializat

Throws error if [configuration](#configuration) is not set.

##### setDebugScriptlets() (MV2 only)

type: `(isDebugScriptlets: boolean) => void`

Updates [debugScriptlets](#debugscriptlets) configuration value
without re-initialization of engine.

Throws error if [configuration](#configuration) is not set.

##### setStealthModeEnabled() (MV2 only)

type: `(value: isStealthModeEnabled) => Promise<void>`
Expand Down Expand Up @@ -566,7 +583,7 @@ type: `TabReloadEvent`

Dispatched on tab reload.

#### applyBasicRule
#### applyBasicRule

type: `ApplyBasicRuleEvent`

Expand All @@ -576,7 +593,7 @@ Dispatched on request block or allowlist rule matching.

type: `ApplyCosmeticRuleEvent`

Dispatched on elemhide, css or html rule applying.
Dispatched on elemhide, css or html rule applying.

#### applyCspRule

Expand Down Expand Up @@ -649,7 +666,7 @@ Event channel for [filtering log events](#filtering-log-api-mv2-only).
### methods
#### addEventListener()

type:
type:
```
<T extends FilteringEventType>(type: T, listener: FilteringLogListener<ExtractedFilteringLogEvent<T>>) => void
```
Expand Down
5 changes: 5 additions & 0 deletions packages/tswebextension/src/lib/common/configuration.ts
Expand Up @@ -113,6 +113,11 @@ export const settingsConfigValidator = zod.object({
*/
collectStats: zod.boolean(),

/**
* Enables verbose scriptlets logging if true.
*/
debugScriptlets: zod.boolean().default(false),

/**
* Enables stealth mode if true.
*/
Expand Down
10 changes: 10 additions & 0 deletions packages/tswebextension/src/lib/mv2/background/app.ts
Expand Up @@ -258,6 +258,16 @@ MessageHandlerMV2
this.configuration.settings.collectStats = isCollectStats;
}

/**
* Updates `debugScriptlets` configuration value without re-initialization of engine.
*
* @throws Error if {@link configuration} not set.
* @param isDebugScriptlets `debugScriptlets` config value.
*/
public setDebugScriptlets(isDebugScriptlets: boolean): void {
this.configuration.settings.debugScriptlets = isDebugScriptlets;
}

/**
* Updates `stealthModeEnabled` configuration value without re-initialization of engine.
* Also updates webRTC privacy.network settings on demand.
Expand Down
Expand Up @@ -176,9 +176,8 @@ export class CosmeticApi extends CosmeticApiCommon {
if (configuration) {
const { settings } = configuration;
if (settings) {
if (settings.collectStats) {
debug = true;
}
// https://github.com/AdguardTeam/AdguardBrowserExtension/issues/2584
debug = settings.debugScriptlets;
}
}

Expand Down
Expand Up @@ -15,6 +15,7 @@ describe('configuration validator', () => {
filteringEnabled: true,
stealthModeEnabled: true,
collectStats: true,
debugScriptlets: false,
allowlistInverted: false,
allowlistEnabled: false,
documentBlockingPageUrl: 'https://example.org',
Expand Down
Expand Up @@ -13,6 +13,7 @@ export const getConfigurationMv2Fixture = (): ConfigurationMV2 => ({
filteringEnabled: true,
stealthModeEnabled: true,
collectStats: true,
debugScriptlets: false,
allowlistInverted: false,
allowlistEnabled: false,
documentBlockingPageUrl: 'https://example.org',
Expand Down

0 comments on commit 3d6c256

Please sign in to comment.