Browser is a browser proxy class. Encapsulate some of the features provided by the browser and native JavaScript.

Browser 是浏览器代理类。封装浏览器及原生 js 提供的一些功能。

构造函数

属性

bundles: Map<string, any> = ...

The loaded bundles.

已载入的脚本集。

canvas: any

The global offline canvas (not the main canvas), used primarily for measuring text and obtaining image data.

全局离线画布(非主画布),主要用来测量文本和获取图像数据。

context: CanvasRenderingContext2D

The rendering context of the global offline canvas (not the main canvas).

全局离线画布上绘图的环境(非主画布)。

isTouchDevice: boolean

Indicates whether the environment supports touch input.

表示环境是否支持触摸输入。

miniGameContext: any

The service object for mini-game platform services.

小游戏平台服务对象。

onAlipayMiniGame: boolean

Indicates whether the current environment is an Alipay mini-game.

表示当前环境是否是支付宝小游戏。

onAndroid: boolean

Indicates whether the current environment is within an Android device.

表示当前环境是否在 Android 设备内。

onBDMiniGame: boolean

Indicates whether the current environment is a Baidu mini-game.

表示当前环境是否是百度小游戏。

onBLMiniGame: boolean

Indicates whether the current environment is a BILIBILI mini-game.

表示当前环境是否是 BILIBILI 小游戏。

onChrome: boolean

Indicates whether the current environment is within Chrome.

表示当前环境是否在 Chrome 内。

onEdge: boolean

Indicates whether the current environment is the Edge browser.

表示当前环境是否是 Edge 浏览器。

onHWMiniGame: boolean

Indicates whether the current environment is a Huawei mini-game.

表示当前环境是否是华为快游戏。

onIE: boolean

Indicates whether the current environment is within the Internet Explorer browser.

表示当前环境是否在 Internet Explorer 浏览器内。

onIOS: boolean

Indicates whether the current environment is within an iOS device.

表示当前环境是否在 IOS 设备内。

onIPad: boolean

Indicates whether the current environment is within an iPad.

表示当前环境是否在 iPad 内。

onIPhone: boolean

Indicates whether the current environment is within an iPhone.

表示当前环境是否在 iPhone 内。

onKGMiniGame: boolean

Indicates whether the current environment is a Xiaomi mini-game.

表示当前环境是否是小米小游戏。

onMac: boolean

Indicates whether the current environment is a Mac device.

表示当前环境是否为 Mac 设备。

onMiniGame: boolean

Indicates whether the current environment is a WeChat mini-game.

表示当前环境是否是微信小游戏。

onMobile: boolean

Indicates whether the current environment is a mobile device, including iOS and Android devices.

表示当前环境是否为移动设备,包括 iOS 和 Android 设备。

onMQQBrowser: boolean

Indicates whether the current environment is within the mobile QQ or QQ browser.

表示当前环境是否在移动 QQ 或 QQ 浏览器内。

onOpenHarmonyOS: boolean

Indicates whether the current environment is within an OpenHarmonyOS device.

表示当前环境是否在 OpenHarmonyOS 设备内。

onPC: boolean

Indicates whether the current environment is a PC.

表示当前环境是否为 PC。

onQGMiniGame: boolean

Indicates whether the current environment is an OPPO mini-game.

表示当前环境是否是 OPPO 小游戏。

onQQBrowser: boolean

Indicates whether the current environment is within the QQ browser.

表示当前环境是否在 QQ 浏览器内。

onQQMiniGame: boolean

Indicates whether the current environment is a QQ mini-game on mobile.

表示当前环境是否是手机 QQ 小游戏。

onSafari: boolean

Indicates whether the current environment is within Safari.

表示当前环境是否在 Safari 内。

onTBMiniGame: boolean

Indicates whether the current environment is a Taobao mini-game.

表示当前环境是否是淘宝小游戏。

onTTMiniGame: boolean

Indicates whether the current environment is a TikTok (Douyin) mini-game.

表示当前环境是否是抖音小游戏。

onVVMiniGame: boolean

Indicates whether the current environment is a VIVO mini-game.

表示当前环境是否是 vivo 小游戏。

onWeiXin: boolean

Indicates whether the current environment is within WeChat.

表示当前环境是否在微信内。

onWP: boolean

Indicates whether the current environment is within a Windows Phone device.

表示当前环境是否在 Windows Phone 设备内。

platform: number

The actual platform type, OnMobile and others are determined through UserAgent, which may be faked.

真实平台类型,onMobile等是通过UserAgent判断,可能具有欺骗性

PLATFORM_ANDROID: number = 1
PLATFORM_IOS: number = 2
PLATFORM_PC: number = 0
supportLocalStorage: boolean

Indicates whether the environment supports LocalStorage.

表示环境是否支持 LocalStorage。

supportWebAudio: boolean

Indicates whether the environment supports WebAudio.

表示环境是否支持 WebAudio。

userAgent: string

Browser proxy information.

浏览器代理信息。

访问器

  • get _isMiniGame(): boolean

    返回 boolean

    onMiniGame || onBDMiniGame || onQGMiniGame || onKGMiniGame || onVVMiniGame || onAlipayMiniGame || onQQMiniGame || onBLMiniGame || onTTMiniGame || onHWMiniGame || onTBMiniGame

    Gets whether it is a mini game environment

    获取是否为小游戏环境

  • get clientHeight(): number

    返回 number

    The viewport height of the browser window. The method analyzes the browser information to determine the height, with a priority given to window.innerHeight (includes scrollbar height) > document.body.clientHeight (excluding scrollbar height) > document.documentElement.clientHeight (both do not include scrollbar height). If the former is 0 or undefined, it falls back to the latter.

    浏览器窗口的可视高度。 通过分析浏览器信息获得。浏览器多个属性值优先级为:window.innerHeight(包含滚动条高度) > document.body.clientHeight(不包含滚动条高度) > document.documentElement.clientHeight, 如果前者为 0 或未定义,则选择后者。

  • set clientHeight(value: number): void

    参数

    • value: number

    返回 void

  • get clientWidth(): number

    返回 number

    The viewport width of the browser window. The method analyzes the browser information to determine the width, with a priority given to window.innerWidth (includes scrollbar width) > document.body.clientWidth (does not include scrollbar width). If the former is 0 or undefined, the latter is chosen.

    浏览器窗口的可视宽度。 通过分析浏览器信息获得。浏览器多个属性值优先级为:window.innerWidth(包含滚动条宽度) > document.body.clientWidth(不包含滚动条宽度), 如果前者为 0 或未定义,则选择后者。

  • set clientWidth(value: number): void

    参数

    • value: number

    返回 void

  • get height(): number

    返回 number

    The physical height of the browser window, taking into account the device pixel ratio.

    浏览器窗口的物理高度,考虑了设备像素比。

  • get width(): number

    返回 number

    The physical width of the browser window, taking into account the device pixel ratio.

    浏览器窗口的物理宽度,考虑了设备像素比。

方法

  • 参数

    • type: string

      The type of node to create.

    返回 any

    A reference to the created node object.

    Creates a native browser element of the specified type.

    创建指定类型的浏览器原生节点。

  • 参数

    • id: string

      The id of the node.

    返回 any

    The node object.

    Returns a reference to the first object in the Document object with the specified id.

    返回 Document 对象中拥有指定 id 的第一个对象的引用。

  • 参数

    • name: string

      The name of the parameter.

    返回 string

    The value of the parameter.

    Gets the value of a URL parameter.

    获取 URL 参数的值。

  • 参数

    • src: string

    返回 Promise<void>

    Dynamically loads a JavaScript library from the specified source.

    从指定源动态加载 JavaScript 库。

  • 返回 number

    Gets the current timestamp in milliseconds since the epoch.

    获取浏览器当前时间戳,单位为毫秒。

  • 参数

    • ele: any

      The node object to be removed.

    返回 void

    Removes the specified native browser node object from the DOM.

    移除指定的浏览器原生节点对象。