File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
packages/thirdweb/src/utils/web Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " thirdweb " : patch
3+ ---
4+
5+ Add extra mobile detection fo isMobile() function
Original file line number Diff line number Diff 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 */
3358export 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}
You can’t perform that action at this time.
0 commit comments