Browser

Browser

new Browser()

Source:
Properties:
Name Type Description
id string

browser实例的唯一id

isReady boolean

是否为就绪状态,即构建完成,可以获取page

isFront boolean

是否为激活状态

browserManager BrowserManager
options Object

传入的配置信息

Extends

Members

idleTime

Source:

闲置时间 当前非激活时长,激活时会被清0

Methods

(async) init()

Source:

Browser的初始化

getBoundingClientRect()

Source:

获取browser相对于视窗的信息

build()

Source:

Browser的构建

bringToFront()

Source:

将browser提到视窗最前端,相当于多个browser,切换到当前

close()

Source:

关闭browser

(async) pages() → {Array.<Page>}

Source:

获取browser下的所有page实例集合

Returns:
Type
Array.<Page>

getPageById() → {Page}

Source:

通过pageid获取指定page实例

Returns:
Type
Page

frontPage() → {Page}

Source:

获取当前激活的page

Returns:
Type
Page

newPage(urlopt, referreropt) → {Promise.<Page>}

Source:

新建页面

Parameters:
Name Type Attributes Description
url string <optional>

页面跳转地址,不传则跳转到browser的startUrl

referrer string <optional>

referrer,不传则为browser的startUrlReferrer

Returns:

返回构建的page实例

Type
Promise.<Page>

_newPageWithoutReady(opener, urlopt, referreropt) → {Page}

Source:

新建页面, 不等待页面加载完成

Parameters:
Name Type Attributes Description
opener Target

打开当前页面的opener

url string <optional>

页面跳转地址,不传则跳转到browser的startUrl

referrer string <optional>

referrer,不传则为browser的startUrlReferrer

Returns:

返回构建的page实例

Type
Page

Events

back

Source:

当前browser取消激活时触发

front

Source:

当前browser激活时触发

close

Source:

当前browser关闭时触发

new-page

Source:

当前browser新建page时触发, 此时page还未构建完毕

Type:

targetcreated

Source:

打开新标签页时触发

Type:

targetchanged

Source:

打开的页面url变更时触发

Type:

targetdestroyed

Source:

新打开的页面关闭时触发

Type:

Browser

new Browser(browserManager, options)

Source:

Browser构造函数

Parameters:
Name Type Description
browserManager BrowserManager
options Object

传入配置

Properties
Name Type Attributes Description
container Element

DOM容器

autoGcTime number

闲置后的自动回收时间,单位为ms, 为0时为永不回收,默认为0

autoGcLimit number

打开的browser超过autoGcLimit时才开启自动回收, 默认20

pageLoadingTimeout number

页面加载超时时间, 默认10s

createPage boolean

是否新建默认page

devtools boolean <optional>

是否打开控制台

partition string <optional>

session标识,相同的partition共享登录状态

preload string

preload, 理论上必须为当前包的preload/webivew.preload.js, 否则无法通信

startUrl string <optional>

新建tab的初始页面, 不传则为abount:blank

startUrlReferrer string <optional>

打开的startUrl的referrer

webpreferences string <optional>

网页功能的设置

Members

idleTime

Source:

闲置时间 当前非激活时长,激活时会被清0

Methods

(async) init()

Source:

Browser的初始化

getBoundingClientRect()

Source:

获取browser相对于视窗的信息

build()

Source:

Browser的构建

bringToFront()

Source:

将browser提到视窗最前端,相当于多个browser,切换到当前

close()

Source:

关闭browser

(async) pages() → {Array.<Page>}

Source:

获取browser下的所有page实例集合

Returns:
Type
Array.<Page>

getPageById() → {Page}

Source:

通过pageid获取指定page实例

Returns:
Type
Page

frontPage() → {Page}

Source:

获取当前激活的page

Returns:
Type
Page

newPage(urlopt, referreropt) → {Promise.<Page>}

Source:

新建页面

Parameters:
Name Type Attributes Description
url string <optional>

页面跳转地址,不传则跳转到browser的startUrl

referrer string <optional>

referrer,不传则为browser的startUrlReferrer

Returns:

返回构建的page实例

Type
Promise.<Page>

_newPageWithoutReady(opener, urlopt, referreropt) → {Page}

Source:

新建页面, 不等待页面加载完成

Parameters:
Name Type Attributes Description
opener Target

打开当前页面的opener

url string <optional>

页面跳转地址,不传则跳转到browser的startUrl

referrer string <optional>

referrer,不传则为browser的startUrlReferrer

Returns:

返回构建的page实例

Type
Page

Events

back

Source:

当前browser取消激活时触发

front

Source:

当前browser激活时触发

close

Source:

当前browser关闭时触发

new-page

Source:

当前browser新建page时触发, 此时page还未构建完毕

Type:

targetcreated

Source:

打开新标签页时触发

Type:

targetchanged

Source:

打开的页面url变更时触发

Type:

targetdestroyed

Source:

新打开的页面关闭时触发

Type: