1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-8582] Move Safari browser check to libs/platform (#11007)

This commit is contained in:
Victoria League
2024-09-16 15:36:05 -04:00
committed by GitHub
parent 26f3dcfc66
commit 112bad03b1
4 changed files with 51 additions and 4 deletions

View File

@@ -0,0 +1 @@
export * from "./services/browser-service";

View File

@@ -0,0 +1,41 @@
import { isBrowserSafariApi } from "./browser-service";
describe("browser-service", () => {
describe("isBrowserSafariApi", () => {
it("returns true if browser is safari", () => {
jest
.spyOn(navigator, "userAgent", "get")
.mockReturnValue(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15",
);
const result = isBrowserSafariApi();
expect(result).toBe(true);
});
it("returns false if browser is chrome", () => {
jest
.spyOn(navigator, "userAgent", "get")
.mockReturnValue(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
);
const result = isBrowserSafariApi();
expect(result).toBe(false);
});
it("returns false if browser is firefox", () => {
jest
.spyOn(navigator, "userAgent", "get")
.mockReturnValue(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:130.0) Gecko/20100101 Firefox/130.0",
);
const result = isBrowserSafariApi();
expect(result).toBe(false);
});
});
});

View File

@@ -0,0 +1,7 @@
export function isBrowserSafariApi(): boolean {
return (
navigator.userAgent.indexOf(" Safari/") !== -1 &&
navigator.userAgent.indexOf(" Chrome/") === -1 &&
navigator.userAgent.indexOf(" Chromium/") === -1
);
}