19 lines
707 B
TypeScript
19 lines
707 B
TypeScript
/** 是否微信内置浏览器 */
|
|
export function isWechatBrowser(): boolean {
|
|
if (typeof navigator === 'undefined') return false;
|
|
return /MicroMessenger/i.test(navigator.userAgent);
|
|
}
|
|
|
|
/** 是否微信小程序 web-view 或独立小程序环境 */
|
|
export function isMiniProgram(): boolean {
|
|
if (typeof window === 'undefined') return false;
|
|
const ua = navigator.userAgent.toLowerCase();
|
|
return ua.includes('miniprogram') || (window as Window & { __wxjs_environment?: string }).__wxjs_environment === 'miniprogram';
|
|
}
|
|
|
|
export function getRuntimePlatform(): 'mini' | 'wechat-h5' | 'browser' {
|
|
if (isMiniProgram()) return 'mini';
|
|
if (isWechatBrowser()) return 'wechat-h5';
|
|
return 'browser';
|
|
}
|