Skip to content

Commit 453a26a

Browse files
POC add priv interface loading
1 parent a63cf7d commit 453a26a

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

src/features/navigator-interface.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
import { defineProperty, DDGPromise } from '../utils'
22
import ContentFeature from '../content-feature'
33

4+
function injectNavigatorInterface (args) {
5+
try {
6+
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
7+
if (navigator.duckduckgo) {
8+
return
9+
}
10+
if (!args.platform || !args.platform.name) {
11+
return
12+
}
13+
defineProperty(Navigator.prototype, 'duckduckgo', {
14+
value: {
15+
platform: args.platform.name,
16+
isDuckDuckGo () {
17+
return DDGPromise.resolve(true)
18+
}
19+
},
20+
enumerable: true,
21+
configurable: false,
22+
writable: false
23+
})
24+
} catch {
25+
// todo: Just ignore this exception?
26+
}
27+
}
28+
429
export default class NavigatorInterface extends ContentFeature {
5-
init (args) {
6-
try {
7-
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
8-
if (navigator.duckduckgo) {
9-
return
10-
}
11-
if (!args.platform || !args.platform.name) {
12-
return
13-
}
14-
defineProperty(Navigator.prototype, 'duckduckgo', {
15-
value: {
16-
platform: args.platform.name,
17-
isDuckDuckGo () {
18-
return DDGPromise.resolve(true)
19-
}
20-
},
21-
enumerable: true,
22-
configurable: false,
23-
writable: false
24-
})
25-
} catch {
26-
// todo: Just ignore this exception?
30+
load (args) {
31+
if (this.matchDomainFeatureSetting('privilegedDomains').length) {
32+
injectNavigatorInterface(args)
2733
}
2834
}
35+
36+
init (args) {
37+
injectNavigatorInterface(args)
38+
}
2939
}

0 commit comments

Comments
 (0)