diff --git a/README.en-US.md b/README.en-US.md index 7d9c9d3..ff14f33 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -785,12 +785,12 @@ You can actively throw errors in the page to interrupt rendering. If your page involves heavy computations or consumes excessive memory, it may crash, causing rendering to be interrupted. -If you're using the high-level API, you can be notified of page crashes through the `error` event of the video instance. +If you're using the high-level API, you can be notified of page crashes through the `pageCrashed` event of the video instance. ```javascript const video = wvc.createSingleVideo({ ... }); -// Output "Page crashed:..." when an error occurs -video.on("error", err => console.error(err)); +// Output crash errors when an error occurs +video.on("pageCrashed", err => console.error(err)); ``` When using the low-level API, you can listen for page crashes through the `crashed` event of the Page instance. diff --git a/README.md b/README.md index 482e271..33ab0aa 100644 --- a/README.md +++ b/README.md @@ -788,12 +788,12 @@ video.on("progress", (progress, synthesizedFrameCount, totalFrameCount) => { 如果您的页面存在大量密集计算或者占用过多的运行内存,页面将可能崩溃,从而导致渲染中断。 -如果使用高级别API,页面崩溃时通过视频实例的 `error` 事件通知。 +如果使用高级别API,页面崩溃时通过视频实例的 `pageCrashed` 事件通知。 ```javascript const video = wvc.createSingleVideo({ ... }); -// 错误时输出 Page crashed:... -video.on("error", err => console.error(err)); +// 错误时输出崩溃错误 +video.on("pageCrashed", err => console.error(err)); ``` 使用低级别API时,页面崩溃时通过Page实例的 `crashed` 事件通知 diff --git a/api/ChunkVideo.js b/api/ChunkVideo.js index ecec91a..d04496e 100644 --- a/api/ChunkVideo.js +++ b/api/ChunkVideo.js @@ -143,7 +143,7 @@ export default class ChunkVideo extends VideoChunk { // 监听页面实例发生的某些内部错误 page.on("error", err => this._emitError("Page error:\n" + err.stack)); // 监听页面是否崩溃,当内存不足或过载时可能会崩溃 - page.on("crashed", err => this._emitError("Page crashed:\n" + err.stack)); + page.on("crashed", err => this.#emitPageCrashedError(err)); if (this.consoleLog) { // 监听页面打印到console的正常日志 page.on("consoleLog", message => logger.log("[page]", message)); @@ -231,4 +231,16 @@ export default class ChunkVideo extends VideoChunk { return await this.#pageAcquireFn(); } + /** + * 发送页面崩溃错误 + * + * @param {Error} err - 错误对象 + */ + #emitPageCrashedError(err) { + if (this.eventNames().includes("pageCrashed")) + this.emit("pageCrashed", err); + else + logger.error("Page crashed:\n" + err.stack); + } + } \ No newline at end of file diff --git a/api/SingleVideo.js b/api/SingleVideo.js index 7da893b..4e27eed 100644 --- a/api/SingleVideo.js +++ b/api/SingleVideo.js @@ -144,7 +144,7 @@ export default class SingleVideo extends Synthesizer { // 监听页面实例发生的某些内部错误 page.on("error", err => this._emitError("Page error:\n" + err.stack)); // 监听页面是否崩溃,当内存不足或过载时可能会崩溃 - page.on("crashed", err => this._emitError("Page crashed:\n" + err.stack)); + page.on("crashed", err => this.#emitPageCrashedError(err)); if (this.consoleLog) { // 监听页面打印到console的正常日志 page.on("consoleLog", message => logger.log("[page]", message)); @@ -226,4 +226,16 @@ export default class SingleVideo extends Synthesizer { return await this.#pageAcquireFn(); } + /** + * 发送页面崩溃错误 + * + * @param {Error} err - 错误对象 + */ + #emitPageCrashedError(err) { + if (this.eventNames().includes("pageCrashed")) + this.emit("pageCrashed", err); + else + logger.error("Page crashed:\n" + err.stack); + } + } \ No newline at end of file