|
| 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 | +
|
0 commit comments