Skip to content

Commit 1929fe3

Browse files
authored
[ConfigFeature] config feature docs update (#1647)
* chore: update readme * chore: update readme + docs
1 parent 5face8a commit 1929fe3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

injected/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,31 @@ The exposed API is a global called contentScopeFeatures and has three methods:
3333

3434
These files stored in the features directory must include an init function and optionally update and load explained in the features lifecycle.
3535

36+
### `ConfigFeature` class
37+
The [ConfigFeature](https://github.com/duckduckgo/content-scope-scripts/blob/main/injected/src/config-feature.js) class is extended by each feature to implement remote config handling. It provides the following methods:
38+
39+
`getFeatureSettingEnabled`
40+
- For simple boolean settings, return true if the setting is 'enabled'
41+
42+
`getFeatureSetting`
43+
- Return a specific setting from the feature settings
44+
45+
`recomputeSiteObject`
46+
- Recomputes the site object for the feature, e.g when the URL has changed.
47+
48+
`ConfigFeature` class is also exportable and can be used by other scripts to build C-S-S like features that can handle remote configuration - currently used in [autofill.js](https://github.com/duckduckgo/duckduckgo-autofill/blob/main/src/site-specific-feature.js) to handle site specific autofill rules.
49+
3650
## Features Lifecycle
3751

3852
There are three stages that the content scope code is hooked into the platform:
39-
- load
53+
- `load`
4054
- This should be reserved for work that should happen that could cause a delay in loading the feature.
4155
- Given the current limitations of how we inject our code we don't have the Privacy Remote Configuration exceptions so authors should be wary of actually loading anything that would modify the page (and potentially breaking it).
4256
- This limitation may be re-addressed in manifest v3
4357
- One exception here is the first party cookie protections that are triggered on init to prevent race conditions.
44-
- init
58+
- `init`
4559
- This is the main place that features are actually loaded into the extension.
46-
- update
60+
- `update`
4761
- This allows the feature to be sent updates from the browser.
4862
- If this is triggered before init, these updates will be queued and triggered straight after.
4963

injected/src/config-feature.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { immutableJSONPatch } from 'immutable-json-patch';
22
import { camelcase, computeEnabledFeatures, matchHostname, parseFeatureSettings, computeLimitedSiteObject } from './utils.js';
33
import { URLPattern } from 'urlpattern-polyfill';
44

5+
/**
6+
* This class is extended by each feature to implement remote config handling:
7+
* - Parsing the remote config, with conditional logic applied,
8+
* - Providing API for features to check if they are enabled,
9+
* - Providing API for features to get their config.
10+
* - For external scripts, it provides API to update the site object for the feature, e.g when the URL has changed.
11+
*/
512
export default class ConfigFeature {
613
/** @type {import('./utils.js').RemoteConfig | undefined} */
714
#bundledConfig;

0 commit comments

Comments
 (0)