Skip to content

Commit

Permalink
跳过无需捕获的帧
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Nov 23, 2023
1 parent 574847f commit b412c93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/CaptureContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ export default class CaptureContext {
return ____screencastCompleted();

}
// 跳过无需捕获的帧
else
await ____skipFrame();

// 开始捕获下一帧
nextFrame.bind(this)();
Expand Down
23 changes: 23 additions & 0 deletions core/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ export default class Page extends EventEmitter {
await this.target.exposeFunction("____screencastCompleted", this.#emitScreencastCompleted.bind(this));
// 暴露CSS动画控制函数
await this.target.exposeFunction("____seekCSSAnimations", this.#seekCSSAnimations.bind(this));
// 暴露跳帧函数
await this.target.exposeFunction("____skipFrame", this.#skipFrame.bind(this));
// 暴露下一帧函数
await this.target.exposeFunction("____captureFrame", this.#captureFrame.bind(this));
// 暴露添加音频函数
Expand Down Expand Up @@ -539,6 +541,27 @@ export default class Page extends EventEmitter {
await Promise.all(seekPromises);
}

/**
* 跳过帧
*/
async #skipFrame() {
if (globalConfig.compatibleRenderingMode)
return;
let timer;
// 帧数据捕获
const frameData = await Promise.race([
this.#cdpSession.send("HeadlessExperimental.beginFrame"),
// 帧渲染超时处理
new Promise(resolve => timer = setTimeout(() => resolve(false), this.beginFrameTimeout))
]);
clearTimeout(timer);
// 帧渲染超时处理
if (frameData === false) {
this.#setState(Page.STATE.UNAVAILABLED);
throw new Error("beginFrame wait timeout");
}
}

/**
* 捕获帧
*/
Expand Down

0 comments on commit b412c93

Please sign in to comment.