-
Notifications
You must be signed in to change notification settings - Fork 17
fix: close window tool #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Greptile SummaryThis PR migrates the Key Changes:
Technical Approach: Infrastructure Improvements: Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as AI Agent/MCP Client
participant Server as HTTP Server (Hono)
participant Tool as closeWindow Tool
participant Context as McpContext
participant Browser as Puppeteer Browser
participant CDP as Chrome DevTools Protocol
Client->>Server: POST /tools/browser_close_window
Server->>Tool: handler(request, response, context)
Tool->>Context: closeWindowByWindowId(windowId)
Context->>Browser: targets()
Browser-->>Context: Target[]
loop For each target
Context->>Context: Extract _targetId (via type assertion)
Context->>CDP: createCDPSession()
CDP-->>Context: CDPSession
Context->>CDP: Browser.getWindowForTarget({targetId})
CDP-->>Context: {windowId: number}
alt windowId matches
Context->>CDP: Target.closeTarget({targetId})
Note over Context: Bypasses beforeunload dialogs
Context->>Context: closedCount++
end
Context->>CDP: session.detach()
end
alt closedCount === 0
Context-->>Tool: throw Error("No targets found")
Tool-->>Client: Error response
else closedCount > 0
Context-->>Tool: Success
Tool->>Tool: response.appendResponseLine()
Tool->>Tool: response.setIncludePages(true)
Tool-->>Client: Success response with pages
end
|
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
| if (env.BROWSEROS_CDP_PORT) { | ||
| chromiumArgs.push(`--browseros-cdp-port=${env.BROWSEROS_CDP_PORT}`) | ||
| // Enable HTTP-based CDP so the server can connect | ||
| chromiumArgs.push(`--remote-debugging-port=${env.BROWSEROS_CDP_PORT}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed. The chromium starts the CDP port on BROWSEROS_CDP_PORT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is not working, there might be bug on chromium I'll take a look. let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes its not working before that, After adding, cdp tools are added.
| if (env.BROWSEROS_CDP_PORT) { | ||
| chromiumArgs.push(`--browseros-cdp-port=${env.BROWSEROS_CDP_PORT}`) | ||
| // Enable HTTP-based CDP so the server can connect | ||
| chromiumArgs.push(`--remote-debugging-port=${env.BROWSEROS_CDP_PORT}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is not working, there might be bug on chromium I'll take a look. let me know.
No description provided.