Skip to content

Commit

Permalink
增加浏览器启动超时和协议超时参数透传
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Dec 2, 2023
1 parent 7303d50 commit f09677d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ wvc.config({
browserDisableDevShm: false,
// 浏览器可执行文件路径,设置后将禁用内部的浏览器,建议您默认使用内部的浏览器以确保功能完整性
browserExecutablePath: "...",
// 浏览器启动超时时间(毫秒),设置等待浏览器启动超时时间
browserLaunchTimeout: 30000,
// 浏览器协议通信超时时间(毫秒),设置CDP协议通信超时时间
browserProtocolTimeout: 180000,
// 是否允许不安全的上下文,默认禁用,开启后能够导航到不安全的URL,但由于不安全上下文限制,将无法在页面中使用动态图像和内嵌视频
allowUnsafeContext: false,
// 兼容渲染模式,MacOS中需要启用,其它环境不建议启用,启用后将禁用HeadlessExperimental.beginFrame API调用改为普通的Page.screenshot
Expand Down
4 changes: 3 additions & 1 deletion core/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ export default class Browser {
// 忽略HTTPS错误
ignoreHTTPSErrors: true,
// 浏览器启动超时时间(毫秒)
timeout: 30000,
timeout: _.defaultTo(globalConfig.browserLaunchTimeout, 30000),
// 是否输出调试信息到控制台
dumpio: _.defaultTo(globalConfig.browserDebug, false),
// 是否使用管道通信
pipe: false,
// 协议超时时间(毫秒)
protocolTimeout: _.defaultTo(globalConfig.browserProtocolTimeout, 180000),
// 用户目录路径
userDataDir: "tmp/browser",
// 浏览器启动参数
Expand Down
10 changes: 10 additions & 0 deletions docs/api-reference-high-level.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
<td>string</td>
<td>浏览器可执行文件路径,设置后将禁用内部的浏览器,建议您默认使用内部的浏览器以确保功能完整性</td>
</tr>
<tr>
<td>browserLaunchTimeout</td>
<td>number</td>
<td>浏览器启动超时时间(毫秒),设置等待浏览器启动超时时间</td>
</tr>
<tr>
<td>browserProtocolTimeout</td>
<td>number</td>
<td>浏览器协议通信超时时间(毫秒),设置CDP协议通信超时时间</td>
</tr>
<tr>
<td>allowUnsafeContext</td>
<td>boolean</td>
Expand Down
18 changes: 18 additions & 0 deletions lib/global-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ export default {
*/
browserExecutablePath: null,

/**
* 浏览器启动超时时间(毫秒)
*
* 设置等待浏览器启动超时时间
*
* @type {string}
*/
browserLaunchTimeout: 30000,

/**
* 浏览器协议通信超时时间(毫秒)
*
* 设置CDP协议通信超时时间
*
* @type {string}
*/
browserProtocolTimeout: 180000,

/**
* 是否允许不安全的上下文
*
Expand Down

0 comments on commit f09677d

Please sign in to comment.