fix(cleaner): capture video reference before page close for rename
page.video() may return null after page.close(), so the video reference must be captured before closing the detail page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1278,25 +1278,24 @@ export class CleanerService {
|
||||
})
|
||||
|
||||
log.debug('[详情页面清理] 准备关闭详情页面', { pageUrl: detailPage.url() })
|
||||
// Capture video reference before closing — page.video() may return null after close
|
||||
const video = this.videoDir ? detailPage.video() : null
|
||||
await detailPage.close()
|
||||
log.debug('[详情页面清理完成] 详情页已关闭')
|
||||
|
||||
// Rename video file to order number if video recording is enabled
|
||||
if (this.videoDir && expectedOrderNumber) {
|
||||
if (video && expectedOrderNumber) {
|
||||
try {
|
||||
const video = detailPage.video()
|
||||
if (video) {
|
||||
const originalPath = await video.path()
|
||||
if (originalPath && fs.existsSync(originalPath)) {
|
||||
const ext = path.extname(originalPath) || '.webm'
|
||||
const orderVideoPath = path.join(this.videoDir, `${expectedOrderNumber}${ext}`)
|
||||
// Avoid overwriting existing file (e.g. retry)
|
||||
const finalPath = fs.existsSync(orderVideoPath)
|
||||
? path.join(this.videoDir, `${expectedOrderNumber}_${Date.now()}${ext}`)
|
||||
: orderVideoPath
|
||||
fs.renameSync(originalPath, finalPath)
|
||||
log.debug('[视频录制] 视频已重命名', { from: originalPath, to: finalPath })
|
||||
}
|
||||
const originalPath = await video.path()
|
||||
if (originalPath && fs.existsSync(originalPath)) {
|
||||
const ext = path.extname(originalPath) || '.webm'
|
||||
const orderVideoPath = path.join(this.videoDir!, `${expectedOrderNumber}${ext}`)
|
||||
// Avoid overwriting existing file (e.g. retry)
|
||||
const finalPath = fs.existsSync(orderVideoPath)
|
||||
? path.join(this.videoDir!, `${expectedOrderNumber}_${Date.now()}${ext}`)
|
||||
: orderVideoPath
|
||||
fs.renameSync(originalPath, finalPath)
|
||||
log.debug('[视频录制] 视频已重命名', { from: originalPath, to: finalPath })
|
||||
}
|
||||
} catch (videoError) {
|
||||
log.warn('[视频录制] 重命名视频失败', {
|
||||
|
||||
Reference in New Issue
Block a user