Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

priv info #479

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/features/navigator-interface.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineProperty, DDGPromise } from '../utils'
import ContentFeature from '../content-feature'

function injectNavigatorInterface (args) {
function injectNavigatorInterface (args, privileged) {
try {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
if (navigator.duckduckgo) {
Expand All @@ -10,13 +10,20 @@ function injectNavigatorInterface (args) {
if (!args.platform || !args.platform.name) {
return
}
const interfaceOut = {
platform: args.platform.name,
isDuckDuckGo () {
return DDGPromise.resolve(true)
}
}
if (privileged) {
interfaceOut.privileged = {
version: args.platform.version,
configVersion: args.remoteConfigVersion
}
}
defineProperty(Navigator.prototype, 'duckduckgo', {
value: {
platform: args.platform.name,
isDuckDuckGo () {
return DDGPromise.resolve(true)
}
},
value: interfaceOut,
enumerable: true,
configurable: false,
writable: false
Expand All @@ -29,11 +36,11 @@ function injectNavigatorInterface (args) {
export default class NavigatorInterface extends ContentFeature {
load (args) {
if (this.matchDomainFeatureSetting('privilegedDomains').length) {
injectNavigatorInterface(args)
injectNavigatorInterface(args, true)
}
}

init (args) {
injectNavigatorInterface(args)
injectNavigatorInterface(args, false)
}
}