feat(erp): conditionally enable Playwright video recording on login

When recordVideo and videoDir are set in ErpConfig, pass Playwright's
recordVideo option to browser.newContext() so sessions are automatically
captured on context close.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-04-17 13:42:46 +08:00
parent 1ff78c11c9
commit 278deb9da4

View File

@@ -47,13 +47,23 @@ export class ErpAuthService {
log.debug('浏览器已启动', { headless: this.config.headless ?? false })
const context = await browser.newContext({
const contextOptions: Parameters<typeof browser.newContext>[0] = {
acceptDownloads: true,
viewport: { width: 1920, height: 1080 },
ignoreHTTPSErrors: true, // Ignore SSL certificate errors
// Disable web security for internal VPN
javaScriptEnabled: true
})
}
if (this.config.recordVideo && this.config.videoDir) {
contextOptions.recordVideo = {
dir: this.config.videoDir,
size: { width: 1920, height: 1080 }
}
log.info('Video recording enabled', { dir: this.config.videoDir })
}
const context = await browser.newContext(contextOptions)
const page = await context.newPage()
attachPageDiagnostics(page)