feat: wrap user callback in try catch

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Simon
2026-01-10 19:19:20 +08:00
parent 6b0b1218ac
commit 0c0c76fdd8

View File

@@ -370,8 +370,18 @@ export class PageAgent extends EventTarget {
const systemInstructions = instructions.system?.trim()
const url = await this.pageController.getCurrentUrl()
const pageInstructions = instructions.getPageInstructions?.(url)?.trim()
let pageInstructions: string | undefined
if (instructions.getPageInstructions) {
try {
pageInstructions = instructions.getPageInstructions(url)?.trim()
} catch (error) {
console.error(
chalk.red('[PageAgent] Failed to execute getPageInstructions callback:'),
error
)
}
}
if (!systemInstructions && !pageInstructions) return ''
let result = '<instructions>\n'