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

feat: add short circuit to allow popups in supported browsers #116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
31 changes: 19 additions & 12 deletions src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
);
}

Expand Down
22 changes: 22 additions & 0 deletions src/device.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
11 changes: 11 additions & 0 deletions test/tests/device/supportsPopups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
Loading