Skip to content

Commit c7d752e

Browse files
[SDK] Enhance isMobile() detection with additional mobile signals
1 parent b4d365b commit c7d752e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

.changeset/smooth-worlds-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add extra mobile detection for isMobile() function

packages/thirdweb/src/utils/web/isMobile.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,48 @@ function isIOS(): boolean {
2727
: false;
2828
}
2929

30+
/**
31+
* @internal
32+
*/
33+
function hasTouchScreen(): boolean {
34+
if (typeof window === "undefined" || typeof navigator === "undefined") {
35+
return false;
36+
}
37+
return (
38+
"ontouchstart" in window ||
39+
navigator.maxTouchPoints > 0 ||
40+
// @ts-expect-error - msMaxTouchPoints is IE specific
41+
navigator.msMaxTouchPoints > 0
42+
);
43+
}
44+
45+
/**
46+
* @internal
47+
*/
48+
function hasMobileAPIs(): boolean {
49+
if (typeof window === "undefined") {
50+
return false;
51+
}
52+
return "orientation" in window || "onorientationchange" in window;
53+
}
54+
3055
/**
3156
* @internal
3257
*/
3358
export function isMobile(): boolean {
34-
return isAndroid() || isIOS();
59+
// Primary signal: OS detection via user agent
60+
const isMobileOS = isAndroid() || isIOS();
61+
62+
if (isMobileOS) {
63+
return true;
64+
}
65+
66+
// Secondary signal: catch edge cases like webviews with modified user agents
67+
// Both touch capability AND mobile-specific APIs must be present to avoid
68+
// false positives on touch-enabled desktops
69+
if (hasTouchScreen() && hasMobileAPIs()) {
70+
return true;
71+
}
72+
73+
return false;
3574
}

0 commit comments

Comments
 (0)