Skip to content

Commit

Permalink
增加允许不安全上下文选项
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Oct 10, 2023
1 parent ababa68 commit 619caba
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ wvc.config({
browserUseGPU: true,
// Path to the browser executable file; setting this will disable the internal browser; it's recommended to use the internal browser for completeness
browserExecutablePath: "...",
// Allow unsafe contexts, false by default. Once enabled, users can navigate to unsafe URLs, but due to unsafe context restrictions, dynamic images and embedded videos cannot be used on the page
allowUnsafeContext: false,
// Compatible rendering mode; not recommended to enable; enabling this will disable HeadlessExperimental.beginFrame API calls and use regular Page.screenshot, which can lead to decreased rendering performance and frame rate desynchronization in some animations; you can try enabling it if you encounter the error "TargetCloseError: Protocol error (HeadlessExperimental.beginFrame): Target closed"
compatibleRenderingMode: false,
// Minimum number of browser instances in the resource pool
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ wvc.config({
browserDisableDevShm: false,
// 浏览器可执行文件路径,设置后将禁用内部的浏览器,建议您默认使用内部的浏览器以确保功能完整性
browserExecutablePath: "...",
// 是否允许不安全的上下文,默认禁用,开启后能够导航到不安全的URL,但由于不安全上下文限制,将无法在页面中使用动态图像和内嵌视频
allowUnsafeContext: false,
// 兼容渲染模式,不建议启用,启用后将禁用HeadlessExperimental.beginFrame API调用改为普通的Page.screenshot
// 这会导致渲染性能下降,且部分动画可能帧率无法同步,当你遭遇 TargetCloseError: Protocol error (HeadlessExperimental.beginFrame): Target closed 错误的时候可以尝试开启它
compatibleRenderingMode: false,
Expand Down
2 changes: 1 addition & 1 deletion core/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class Page extends EventEmitter {
// 清除资源
this.#clearResources();
// 检查URL
// this.#checkURL(url);
!globalConfig.allowUnsafeContext && this.#checkURL(url);
// 开始CDP会话
await this.#startCDPSession();
// 监听CSS动画
Expand Down
5 changes: 5 additions & 0 deletions docs/api-reference-high-level.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
<td>string</td>
<td>浏览器可执行文件路径,设置后将禁用内部的浏览器,建议您默认使用内部的浏览器以确保功能完整性</td>
</tr>
<tr>
<td>allowUnsafeContext</td>
<td>boolean</td>
<td>默认禁用,开启后能够导航到不安全的URL,但由于不安全上下文限制,将无法在页面中使用动态图像和内嵌视频</td>
</tr>
<tr>
<td>compatibleRenderingMode</td>
<td>boolean</td>
Expand Down
8 changes: 8 additions & 0 deletions lib/global-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ export default {
*/
browserExecutablePath: null,

/**
* 是否允许不安全的上下文
*
* 默认禁用,开启后能够导航到不安全的URL
* 但由于不安全上下文限制,将无法在页面中使用动态图像和内嵌视频
*/
allowUnsafeContext: false,

/**
* 兼容渲染模式
*
Expand Down

0 comments on commit 619caba

Please sign in to comment.