mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-21 16:18:28 +01:00
[PM-8582] Move Safari browser check to libs/platform (#11007)
This commit is contained in:
parent
26f3dcfc66
commit
112bad03b1
@ -1,6 +1,7 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { DeviceType } from "@bitwarden/common/enums";
|
||||
import { isBrowserSafariApi } from "@bitwarden/platform";
|
||||
|
||||
import { TabMessage } from "../../types/tab-messages";
|
||||
import { BrowserPlatformUtilsService } from "../services/platform-utils/browser-platform-utils.service";
|
||||
@ -9,10 +10,7 @@ import { registerContentScriptsPolyfill } from "./browser-api.register-content-s
|
||||
|
||||
export class BrowserApi {
|
||||
static isWebExtensionsApi: boolean = typeof browser !== "undefined";
|
||||
static isSafariApi: boolean =
|
||||
navigator.userAgent.indexOf(" Safari/") !== -1 &&
|
||||
navigator.userAgent.indexOf(" Chrome/") === -1 &&
|
||||
navigator.userAgent.indexOf(" Chromium/") === -1;
|
||||
static isSafariApi: boolean = isBrowserSafariApi();
|
||||
static isChromeApi: boolean = !BrowserApi.isSafariApi && typeof chrome !== "undefined";
|
||||
static isFirefoxOnAndroid: boolean =
|
||||
navigator.userAgent.indexOf("Firefox/") !== -1 && navigator.userAgent.indexOf("Android") !== -1;
|
||||
|
@ -0,0 +1 @@
|
||||
export * from "./services/browser-service";
|
41
libs/platform/src/services/browser-service.spec.ts
Normal file
41
libs/platform/src/services/browser-service.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
7
libs/platform/src/services/browser-service.ts
Normal file
7
libs/platform/src/services/browser-service.ts
Normal 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
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user