Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/core/tools/browserActionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ export async function browserActionTool(
}
}

// Clean up old browser screenshots from API conversation history to prevent memory accumulation
// Only keep the latest screenshot - old ones are no longer needed by the model
if (browserActionResult?.screenshot) {
const apiHistory = cline.apiConversationHistory
for (let i = apiHistory.length - 1; i >= 0; i--) {
const message = apiHistory[i]
if (Array.isArray(message.content)) {
// Filter out old screenshot image blocks
message.content = message.content.filter((block) => {
// Remove base64 image blocks (browser screenshots)
// Keep text blocks and other content
if (
block.type === "image" &&
"source" in block &&
block.source.type === "base64" &&
(block.source.media_type === "image/webp" || block.source.media_type === "image/png")
) {
// This is likely an old browser screenshot - remove it
return false
}
return true
})
}
}
}
Comment on lines +151 to +175
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup logic removes ALL base64 webp/png images from the entire conversation history without distinguishing between browser screenshots and user-provided images. If a user uploads an image in webp or png format during the conversation, it will be incorrectly deleted during browser actions. The filter should only remove images from browser_action_result messages (by checking the message structure) and preserve the latest browser screenshot while removing only older ones. User-provided images in other message types must be preserved.


switch (action) {
case "launch":
case "click":
Expand Down
Loading