From 0c0c76fdd8ee8bd1790ea713a4d78eb290913595 Mon Sep 17 00:00:00 2001 From: Simon <10131203+gaomeng1900@users.noreply.github.com> Date: Sat, 10 Jan 2026 19:19:20 +0800 Subject: [PATCH] feat: wrap user callback in try catch Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/page-agent/src/PageAgent.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/page-agent/src/PageAgent.ts b/packages/page-agent/src/PageAgent.ts index 1390b29..4059df7 100644 --- a/packages/page-agent/src/PageAgent.ts +++ b/packages/page-agent/src/PageAgent.ts @@ -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 = '\n'