Skip to content

Commit b412c93

Browse files
committed
跳过无需捕获的帧
1 parent 574847f commit b412c93

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

core/CaptureContext.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ export default class CaptureContext {
180180
return ____screencastCompleted();
181181

182182
}
183+
// 跳过无需捕获的帧
184+
else
185+
await ____skipFrame();
183186

184187
// 开始捕获下一帧
185188
nextFrame.bind(this)();

core/Page.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ export default class Page extends EventEmitter {
485485
await this.target.exposeFunction("____screencastCompleted", this.#emitScreencastCompleted.bind(this));
486486
// 暴露CSS动画控制函数
487487
await this.target.exposeFunction("____seekCSSAnimations", this.#seekCSSAnimations.bind(this));
488+
// 暴露跳帧函数
489+
await this.target.exposeFunction("____skipFrame", this.#skipFrame.bind(this));
488490
// 暴露下一帧函数
489491
await this.target.exposeFunction("____captureFrame", this.#captureFrame.bind(this));
490492
// 暴露添加音频函数
@@ -539,6 +541,27 @@ export default class Page extends EventEmitter {
539541
await Promise.all(seekPromises);
540542
}
541543

544+
/**
545+
* 跳过帧
546+
*/
547+
async #skipFrame() {
548+
if (globalConfig.compatibleRenderingMode)
549+
return;
550+
let timer;
551+
// 帧数据捕获
552+
const frameData = await Promise.race([
553+
this.#cdpSession.send("HeadlessExperimental.beginFrame"),
554+
// 帧渲染超时处理
555+
new Promise(resolve => timer = setTimeout(() => resolve(false), this.beginFrameTimeout))
556+
]);
557+
clearTimeout(timer);
558+
// 帧渲染超时处理
559+
if (frameData === false) {
560+
this.#setState(Page.STATE.UNAVAILABLED);
561+
throw new Error("beginFrame wait timeout");
562+
}
563+
}
564+
542565
/**
543566
* 捕获帧
544567
*/

0 commit comments

Comments
 (0)