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: 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 = ...
isDomSupported: boolean = true

Indicates whether the environment supports DOM.

表示环境是否支持 DOM。

isIOSHighPerformanceMode: boolean

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

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

isIOSHighPerformanceModePlus: boolean

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

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

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

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 内。

onDevTools: boolean

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

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

onEdge: boolean

Indicates whether the current environment is the Edge browser.

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

onFirefox: boolean

Indicates whether the current environment is the Firefox browser.

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

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.

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

onLayaRuntime: boolean

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

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

onMac: boolean

Indicates whether the current environment is a Mac device.

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

onMiniGame: boolean
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 设备内。

onWXMiniGame: boolean

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

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

platform: number = 0

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

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

PLATFORM_ANDROID = 1

Android platform.

Android 平台。

PLATFORM_IOS = 2

iOS platform.

iOS 平台。

PLATFORM_PC = 0

PC platform.

PC 平台。

platformName: string = ""

The readable name of the platform.

平台的可读名称。

SDKVersion: string = ""

The version of the Platform SDK.

平台 SDK 版本。

systemVersion: string = ""

The version of the system.

系统版本。

userAgent: string

Browser proxy information.

浏览器代理信息。

window: Window & typeof globalThis = ...

访问器

  • 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): void
  • 参数

    • value: number

    返回 void

    Sets the viewport height of the browser window.

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

  • 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): 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

      The type of node to create.

    返回 HTMLElementTagNameMap[K]

    A reference to the created node object.

    Creates a native browser element of the specified type.

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

  • 参数

    • name: string

      The name of the parameter.

    返回 string

    The value of the parameter.

    Gets the value of a URL parameter.

    获取 URL 参数的值。

  • 参数

    • src: string
    • 可选async: boolean

    返回 Promise<void>

    Dynamically loads a JavaScript library from the specified source.

    从指定源动态加载 JavaScript 库。

  • 返回 number

    Gets the current timestamp in milliseconds since the epoch. It is equivalent to performance.now().

    获取浏览器当前时间戳,单位为毫秒。等同于 performance.now()