From 163679d4f388a0a8cb99ee39a55f7364986d4aad Mon Sep 17 00:00:00 2001 From: chrisfarms Date: Wed, 27 Nov 2024 13:56:31 +0000 Subject: [PATCH] detect mobile browsers --- src/runtime/platform/browser.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/runtime/platform/browser.ts b/src/runtime/platform/browser.ts index 681f8bce..daf16942 100644 --- a/src/runtime/platform/browser.ts +++ b/src/runtime/platform/browser.ts @@ -1,5 +1,9 @@ import type { Platform } from '../platform'; +function hasTouchSupport() { + return 'ontouchstart' in window || navigator.maxTouchPoints > 0; +} + const browserPlatform: Platform = { name: 'browser', os: 'web', @@ -12,7 +16,10 @@ const browserPlatform: Platform = { window.open(url, '_blank'); }, - isMobile: false, + isMobile: + /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent, + ) || hasTouchSupport(), isWindows: false, isProduction: import.meta.env.MODE === 'production', isBrowser: true,