Skip to content

Commit 3d9cd9f

Browse files
shakyShaneShane Osbourne
andauthored
Adding docs for message bridge (#1230)
* document message bridge * Added example --------- Co-authored-by: Shane Osbourne <[email protected]>
1 parent 5419f46 commit 3d9cd9f

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ node_modules/
44
.env
55
.build/
66
build/
7-
docs/
7+
/docs
88
/screens
99
test-results/
1010
playwright-report/

injected/docs/message-bridge.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Message Bridge
3+
---
4+
5+
## Description
6+
7+
Message Bridge creates a communication between a website and a browser. It sends and receives messages that conform
8+
to our Messaging standard (eg: it's not a new format!)
9+
10+
- Related Privacy Configuration [feature file](https://github.com/duckduckgo/privacy-configuration/blob/main/features/message-bridge.json)
11+
- Message formats: {@link "Messaging Schema"}
12+
13+
14+
## Integration guide
15+
16+
## Step 1: add `messageSecret` to `$USER_PREFERENCES$`
17+
18+
This feature requires the following to be serialized into `$USER_PREFERENCES$`.
19+
20+
- `"messageSecret": "<some uuid>"`
21+
22+
Without this, the bridge will refuse to be installed.
23+
24+
Example:
25+
26+
```json
27+
{
28+
"...": "...",
29+
"messageSecret": ""
30+
}
31+
```
32+
33+
## Step 2: Enable in remote config
34+
35+
Using the method of your choice, generate a remote config file that has the bridge feature
36+
enabled + some feature & domain combinations.
37+
38+
39+
For example, to enable `aiChat` on `duckduckgo.com` domains - you would place the following override
40+
in the relevant platform file. This is how the per-domain restrictions are enforced in the JavaScript layer.
41+
42+
```json
43+
{
44+
"features": {
45+
"...": "...",
46+
"messageBridge": {
47+
"state": "enabled",
48+
"settings": {
49+
"aiChat": "disabled",
50+
"domains": [
51+
{
52+
"domain": "duckduckgo.com",
53+
"patchSettings": [
54+
{
55+
"op": "replace",
56+
"path": "/aiChat",
57+
"value": "enabled"
58+
}
59+
]
60+
}
61+
]
62+
}
63+
}
64+
}
65+
}
66+
```
67+
68+
**NOTE:** Native platforms should continue to verify the sending domain when any messages are received.
69+
70+
## Example
71+
72+
In a domain where the bridge is enabled, the following API becomes available to the page.
73+
74+
```javascript
75+
const bridge = navigator.duckduckgo?.createMessageBridge?.('exampleFeature');
76+
bridge.notify('pixel');
77+
```
78+
79+
That `notify` ^ call will result in a {@link "Messaging Schema".NotificationMessage "NotificationMessage"} being sent
80+
to the 'native' layer.
81+
82+
```json
83+
{
84+
"context": "contentScopeScriptsIsolated",
85+
"featureName": "exampleFeature",
86+
"method": "pixel"
87+
}
88+
```
89+
90+
Likewise with `Requests` and `Subscriptions` - as far as the 'native' side is concerned, they are handled with the same
91+
Messaging Schema types.
92+
93+

typedoc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { OptionDefaults } from 'typedoc';
22

33
/** @type {Partial<import('typedoc').TypeDocOptions>} */
44
const config = {
5-
projectDocuments: ['special-pages/pages/new-tab/app/new-tab.md'],
5+
// prettier-ignore
6+
projectDocuments: [
7+
'special-pages/pages/new-tab/app/new-tab.md',
8+
'injected/docs/*.md',
9+
],
610
entryPoints: [
711
'injected/entry-points/android.js',
812
'injected/entry-points/apple.js',

0 commit comments

Comments
 (0)