Skip to content

Commit

Permalink
fix: disable popups for firefox on android (#120)
Browse files Browse the repository at this point in the history
* fix: disable popups for firefox on android

* fix: ignore hermes parser from type check

* ci: check in dist folder

* chore(release): 2.7.0

* Revert "chore(release): 2.7.0"

This reverts commit e31976a.

* Revert "ci: check in dist folder"

This reverts commit aec5c01.

* fix: update version to avoid conflicts with existing 2.7.0
  • Loading branch information
ravishekhar authored Feb 13, 2025
1 parent 0817042 commit 48f5dc1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.*/node_modules/eslint-plugin-compat
.*/node_modules/flowgen
.*/node_modules/resolve
.*/node_modules/hermes-parser
.*/dist/module
[include]
[libs]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@krakenjs/belter",
"version": "2.6.0",
"version": "2.7.1",
"description": "Utilities.",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export function isAndroid(ua?: string = getUserAgent()): boolean {
return /Android/.test(ua);
}

export function isFirefoxAndroid(ua?: string = getUserAgent()): boolean {
return isAndroid(ua) && isFirefox(ua);
}

export function isIos(ua?: string = getUserAgent()): boolean {
return /iPhone|iPod|iPad/.test(ua);
}
Expand Down Expand Up @@ -245,6 +249,7 @@ export function supportsPopups(ua?: string = getUserAgent()): boolean {
isAndroidWebview(ua) ||
isOperaMini(ua) ||
isFirefoxIOS(ua) ||
isFirefoxAndroid(ua) ||
isEdgeIOS(ua) ||
isFacebookWebView(ua) ||
isQQBrowser(ua) ||
Expand Down
23 changes: 22 additions & 1 deletion test/tests/device/isFirefox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { isFirefox } from "../../../src/device";
import { isFirefox, isFirefoxAndroid } from "../../../src/device";

describe("isFirefoxIOS", () => {
beforeEach(() => {
Expand All @@ -22,3 +22,24 @@ describe("isFirefoxIOS", () => {
}
});
});

describe("isFirefoxAndroid", () => {
beforeEach(() => {
window.navigator = {};
});
it("should return true when userAgent contains firefox(case insensitive)", () => {
window.navigator.userAgent =
"Mozilla/5.0 (Android 15; Mobile; rv:135.0) Gecko/135.0 Firefox/135.0";
const bool = isFirefoxAndroid();
if (!bool) {
throw new Error(`Expected true, got ${JSON.stringify(bool)}`);
}
});
it("should return false when userAgent does NOT contain firefox(case insensitive)", () => {
window.navigator.userAgent = "fired potato";
const bool = isFirefoxAndroid();
if (bool) {
throw new Error(`Expected false, got ${JSON.stringify(bool)}`);
}
});
});
8 changes: 8 additions & 0 deletions test/tests/device/supportsPopups.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ describe("supportsPopups", () => {
throw new Error(`Expected false, got ${JSON.stringify(bool)}`);
}
});
it("should return false when user agent is firefox on android", () => {
window.navigator.userAgent =
"Mozilla/5.0 (Android 15; Mobile; rv:135.0) Gecko/135.0 Firefox/135.0";
const bool = supportsPopups();
if (bool) {
throw new Error(`Expected false, got ${JSON.stringify(bool)}`);
}
});
it("should return false when isEdgeIOS function returns true", () => {
window.navigator.userAgent = "edgios";
const bool = supportsPopups();
Expand Down

0 comments on commit 48f5dc1

Please sign in to comment.