Skip to content

Commit 57df66f

Browse files
committed
Improve navigate_page_history error messages
Check navigation result and provide specific feedback: - Detect when no previous/next page exists in history - Show timeout errors with duration details - Include actual error messages instead of generic text
1 parent 51a1761 commit 57df66f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/tools/pages.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,33 @@ export const navigatePageHistory = defineTool({
142142
const options = {
143143
timeout: request.params.timeout,
144144
};
145+
145146
try {
147+
let result;
146148
if (request.params.navigate === 'back') {
147-
await page.goBack(options);
149+
result = await page.goBack(options);
150+
} else {
151+
result = await page.goForward(options);
152+
}
153+
154+
// If result is null, navigation wasn't possible (no history)
155+
if (result === null) {
156+
const direction = request.params.navigate === 'back' ? 'previous' : 'next';
157+
response.appendResponseLine(
158+
`Cannot navigate ${request.params.navigate}, no ${direction} page in history.`,
159+
);
160+
}
161+
} catch (error) {
162+
// Provide more specific error messages based on the error type
163+
if (error.message && error.message.includes('timeout')) {
164+
response.appendResponseLine(
165+
`Navigation ${request.params.navigate} timed out after ${request.params.timeout || 30000}ms.`,
166+
);
148167
} else {
149-
await page.goForward(options);
168+
response.appendResponseLine(
169+
`Unable to navigate ${request.params.navigate}: ${error.message || 'Unknown error occurred'}`,
170+
);
150171
}
151-
} catch {
152-
response.appendResponseLine(
153-
`Unable to navigate ${request.params.navigate} in currently selected page.`,
154-
);
155172
}
156173

157174
response.setIncludePages(true);

0 commit comments

Comments
 (0)