-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[PM-9388] Add new device type for DuckDuckGo browser #14708
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
96ab816
ba824c8
8d53b10
abfeeac
106b075
8f9452d
147ecd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ export class WebFileDownloadService implements FileDownloadService { | |
download(request: FileDownloadRequest): void { | ||
const builder = new FileDownloadBuilder(request); | ||
const a = window.document.createElement("a"); | ||
if (!this.platformUtilsService.isSafari()) { | ||
if (!(this.platformUtilsService.isSafari() || this.platformUtilsService.isDuckDuckGo())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we ever accurately identified DuckDuckGo on windows this logic might break down. I think a lot of our There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created a backlog ticket for converting |
||
a.rel = "noreferrer"; | ||
a.target = "_blank"; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// FIXME: Update this file to be type safe and remove this and next line | ||
// @ts-strict-ignore | ||
import { DeviceType } from "@bitwarden/common/enums"; | ||
|
||
import { WebPlatformUtilsService } from "./web-platform-utils.service"; | ||
|
||
describe("Web Platform Utils Service", () => { | ||
|
@@ -114,4 +116,27 @@ describe("Web Platform Utils Service", () => { | |
expect(result).toBe("2022.10.2"); | ||
}); | ||
}); | ||
describe("getDevice", () => { | ||
const originalUserAgent = navigator.userAgent; | ||
|
||
const setUserAgent = (userAgent: string) => { | ||
Object.defineProperty(navigator, "userAgent", { | ||
value: userAgent, | ||
configurable: true, | ||
}); | ||
}; | ||
|
||
afterEach(() => { | ||
// Reset to original after each test | ||
setUserAgent(originalUserAgent); | ||
}); | ||
|
||
test("returns DuckDuckGo browser with example User-Agent", () => { | ||
setUserAgent( | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15 Ddg/18.3.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a generalization of this test would be useful so we can define a lot of inputs and the expected browser a little easier. const testData: { userAgent: string, expectedDevice: DeviceType }[] = [
{
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15 Ddg/18.3.1",
expectedDevice: DeviceType.DuckDuckGoBrowser,
}
]; Also some comments about what the user agent was taken from version, OS, browser type for example. One of the test cases could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added additional tests for all the different browsers, based on current user-agent strings. |
||
); | ||
const result = webPlatformUtilsService.getDevice(); | ||
expect(result).toBe(DeviceType.DuckDuckGoBrowser); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,11 @@ | |
this.browserCache = DeviceType.EdgeBrowser; | ||
} else if (navigator.userAgent.indexOf(" Vivaldi/") !== -1) { | ||
this.browserCache = DeviceType.VivaldiBrowser; | ||
} else if ( | ||
navigator.userAgent.indexOf(" Safari/") !== -1 && | ||
navigator.userAgent.indexOf("Ddg") !== -1 | ||
) { | ||
this.browserCache = DeviceType.DuckDuckGoBrowser; | ||
} else if ( | ||
navigator.userAgent.indexOf(" Safari/") !== -1 && | ||
navigator.userAgent.indexOf("Chrome") === -1 | ||
|
@@ -83,6 +88,10 @@ | |
return this.getDevice() === DeviceType.SafariBrowser; | ||
} | ||
|
||
isDuckDuckGo(): boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should add these anymore. The ideal is that no team needs to do specific client checks and even if they do the |
||
return this.getDevice() === DeviceType.DuckDuckGoBrowser; | ||
} | ||
|
||
isMacAppStore(): boolean { | ||
return false; | ||
} | ||
|
@@ -120,6 +129,10 @@ | |
return true; | ||
} | ||
|
||
supportsSyncDomains(): boolean { | ||
return false; | ||
} | ||
|
||
showToast( | ||
type: "error" | "success" | "warning" | "info", | ||
title: string, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better name for this is
supportsAutofill
my dream would be that this would live on something autofill owned as well but this needs to be used pretty low level and I don't know of a great place it right now so we can leave it.