diff --git a/src/device.js b/src/device.js index 6992592..0347b10 100644 --- a/src/device.js +++ b/src/device.js @@ -226,19 +226,26 @@ export function isMacOsCna(): boolean { return /Macintosh.*AppleWebKit(?!.*Safari)/i.test(userAgent); } +export function isPopupSupportedWebview(ua?: string = getUserAgent()): boolean { + return /FB\/MW/.test(ua); +} + export function supportsPopups(ua?: string = getUserAgent()): boolean { - return !( - isWebView(ua) || - isIosWebview(ua) || - isAndroidWebview(ua) || - isOperaMini(ua) || - isFirefoxIOS(ua) || - isEdgeIOS(ua) || - isFacebookWebView(ua) || - isQQBrowser(ua) || - isElectron() || - isMacOsCna() || - isStandAlone() + return ( + isPopupSupportedWebview(ua) || + !( + isWebView(ua) || + isIosWebview(ua) || + isAndroidWebview(ua) || + isOperaMini(ua) || + isFirefoxIOS(ua) || + isEdgeIOS(ua) || + isFacebookWebView(ua) || + isQQBrowser(ua) || + isElectron() || + isMacOsCna() || + isStandAlone() + ) ); } diff --git a/src/device.test.js b/src/device.test.js new file mode 100644 index 0000000..b2556fe --- /dev/null +++ b/src/device.test.js @@ -0,0 +1,22 @@ +/* @flow */ +import { describe, test, expect } from "vitest"; + +import { supportsPopups, isPopupSupportedWebview } from "./device"; + +describe("supportsPopups", () => { + test("returns true when short circuited", () => { + const ua = `Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) + AppleWebKit/537.36 (KHTML, like Gecko) + Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/44.25.0.1;FB/MW]`; + expect(supportsPopups(ua)).toBe(true); + }); +}); + +describe("isPopupSupportedWebview", () => { + test("returns true when fb webview supported user agent", () => { + const ua = `Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) + AppleWebKit/537.36 (KHTML, like Gecko) + Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/44.25.0.1;FB/MW]`; + expect(isPopupSupportedWebview(ua)).toBe(true); + }); +}); diff --git a/test/tests/device/supportsPopups.js b/test/tests/device/supportsPopups.js index 565d00f..466c58a 100644 --- a/test/tests/device/supportsPopups.js +++ b/test/tests/device/supportsPopups.js @@ -133,6 +133,17 @@ describe("supportsPopups", () => { throw new Error(`Expected true, got ${JSON.stringify(bool)}`); } }); + it("should return true when in facebook multiwindow experiment", () => { + window.navigator.userAgent = `Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) + AppleWebKit/537.36 (KHTML, like Gecko) + Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/44.25.0.1;FB/MW]`; + const result = supportsPopups(); + if (!result) { + throw new Error( + `Expected to support popups, got ${JSON.stringify(result)}` + ); + } + }); }); describe("WebView on Android", () => { it("should return false when it is a valid WebView UA in KitKat to Lollipop", () => {