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

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

构造函数

属性

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

已载入的脚本集。

The loaded bundles.

canvas: HTMLCanvas

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

The global offscreen canvas, used primarily for measuring text and obtaining image data.

context: CanvasRenderingContext2D

全局离屏画布上绘图的环境。

The rendering context of the global offscreen canvas.

document: Document = ...

全局 document 对象。

The global document object.

isDomSupported: boolean = true

表示环境是否支持 DOM。

Indicates whether the environment supports DOM.

isIOSHighPerformanceMode: boolean

表示环境是否支持 iOS 设备的高性能模式。

Indicates whether the environment supports high-performance mode on iOS devices.

isIOSHighPerformanceModePlus: boolean

表示环境是否支持 iOS 设备的高性能+模式。

Indicates whether the environment supports high-performance+ mode on iOS devices.

isTouchDevice: boolean

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

Indicates whether the environment supports touch input.

mainCanvas: HTMLCanvas

全局画布。

The global canvas.

onAlipayMiniGame: boolean

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

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

onAndroid: boolean

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

Indicates whether the current environment is within an Android device.

onBDMiniGame: boolean

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

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

onBLMiniGame: boolean

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

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

onChrome: boolean

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

Indicates whether the current environment is within Chrome.

onDevTools: boolean

表示当前环境是否运行在开发工具中。

Indicates whether the current environment is running in a development tool.

onEdge: boolean

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

Indicates whether the current environment is the Edge browser.

onFirefox: boolean

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

Indicates whether the current environment is the Firefox browser.

onHWMiniGame: boolean

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

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

onIE: boolean

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

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

onIOS: boolean

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

Indicates whether the current environment is within an iOS device.

onIPad: boolean

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

Indicates whether the current environment is within an iPad.

onIPhone: boolean

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

Indicates whether the current environment is within an iPhone.

onKGMiniGame: boolean

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

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

onLayaRuntime: boolean

表示当前环境是否运行在 LayaAir Native Runtime。

Indicates whether the current environment is running on LayaAir Native Runtime.

onMac: boolean

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

Indicates whether the current environment is a Mac device.

onMiniGame: boolean
onMobile: boolean

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

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

onMQQBrowser: boolean

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

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

onOpenHarmonyOS: boolean

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

Indicates whether the current environment is within an OpenHarmonyOS device.

onPC: boolean

表示当前环境是否为 PC。

Indicates whether the current environment is a PC.

onQGMiniGame: boolean

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

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

onQQBrowser: boolean

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

Indicates whether the current environment is within the QQ browser.

onQQMiniGame: boolean

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

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

onSafari: boolean

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

Indicates whether the current environment is within 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

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

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

onWeiXin: boolean

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

Indicates whether the current environment is within WeChat.

onWP: boolean

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

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

onWXMiniGame: boolean

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

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

platform: number = 0

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

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

PLATFORM_ANDROID = 1

Android 平台。

Android platform.

PLATFORM_IOS = 2

iOS 平台。

iOS platform.

PLATFORM_PC = 0

PC 平台。

PC platform.

platformName: string = ""

平台的可读名称。

The readable name of the platform.

SDKVersion: string = ""

平台 SDK 版本。

The version of the Platform SDK.

systemVersion: string = ""

系统版本。

The version of the system.

userAgent: string

浏览器代理信息。

Browser proxy information.

window: Window & typeof globalThis = ...

全局 window 对象。

The global window object.

访问器

  • get clientHeight(): number
  • 返回 number

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

    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.

  • set clientHeight(value): void
  • 参数

    • value: number

    返回 void

    设置浏览器窗口的可视高度。

    Sets the viewport height of the browser window.

  • get clientWidth(): number
  • 返回 number

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

    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.

  • set clientWidth(value): void
  • 参数

    • value: number

    返回 void

    设置浏览器窗口的可视宽度。

    Sets the viewport width of the browser window.

  • get container(): HTMLElement
  • 返回 HTMLElement

    用来存放画布元素的容器,方便对画布进行控制。

    The canvas container that holds the canvas element, facilitating control over the canvas.

  • 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.

方法

  • 类型参数

    • K extends keyof HTMLElementTagNameMap

    参数

    • tagName: K

      要创建的节点类型。

    返回 HTMLElementTagNameMap[K]

    创建的节点对象的引用。

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

    Creates a native browser element of the specified type.

  • 参数

    • id: string

      元素的id。

    返回 HTMLElement

    获取到的元素。

    通过id获取HTMLElement。

    Get the HTMLElement by its ID.

  • 参数

    • name: string

      参数的名称。

    返回 string

    参数的值。

    获取 URL 参数的值。

    Gets the value of a URL parameter.

  • 参数

    • src: string
    • 可选async: boolean

    返回 Promise<void>

    从指定源动态加载 JavaScript 库。

    Dynamically loads a JavaScript library from the specified source.

  • 返回 number

    获取从页面加载开始的高精度时间,单位为毫秒。等同于 performance.now()

    Gets the high-resolution time in milliseconds since the page started loading or since the navigation start time. It is equivalent to performance.now().

  • 参数

    • ele: HTMLElement

      要移除的元素。

    返回 void

    移除指定HTMLElement元素。

    Removes the specified HTMLElement.