Skip to content

fix: restore URL content fetching for @url context menu mentions#11858

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/contextmenu-url-fetch-content
Draft

fix: restore URL content fetching for @url context menu mentions#11858
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/contextmenu-url-fetch-content

Conversation

@roomote-v0
Copy link
Contributor

@roomote-v0 roomote-v0 bot commented Mar 4, 2026

Related GitHub Issue

Closes: #11856

Description

This PR attempts to address Issue #11856 where the @url context menu option ("Paste URL to fetch contents") was not actually fetching any URL content. After the browser feature was removed, URL mentions in parseMentions() were only replaced with a quoted string reference without fetching the actual page content.

Changes:

  • New fetchUrlContent utility (src/core/mentions/fetchUrlContent.ts): Uses axios for HTTP requests and cheerio for HTML text extraction. Strips scripts, styles, nav, footer, and other non-content elements, preferring <main>/<article> content. Handles non-HTML content types (plain text, JSON) as raw text. Includes timeout, redirect limits, and content length truncation.

  • Updated parseMentions() (src/core/mentions/index.ts): Added URL mention handling in the mention processing loop. URL content is now fetched and included as a MentionContentBlock with type "url", consistent with how file/folder mentions work. Error handling provides informative messages when fetch fails.

  • Updated text replacement: URL mentions now show "(see below for fetched content)" to indicate content will follow, matching the pattern used by other mention types.

No new dependencies were added -- axios and cheerio are already in package.json.

Feedback and guidance are welcome.

Test Procedure

  • Added 7 tests in fetchUrlContent.spec.ts covering: HTML extraction, non-HTML content, JSON handling, content truncation, error propagation, body fallback, and missing content-type.
  • Added 4 tests in index.spec.ts covering: text replacement, content block generation, error handling, and truncation indication.
  • All 11 tests pass. Lint and type checks pass across the monorepo.

Run tests:

cd src && npx vitest run core/mentions/__tests__/fetchUrlContent.spec.ts core/mentions/__tests__/index.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: I have considered if my changes require documentation updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The implementation uses a lightweight approach with axios + cheerio for URL content extraction instead of the previously removed browser/puppeteer-based approach. This avoids the complexity and resource overhead of a headless browser while still providing useful page content for most websites. JavaScript-rendered content will not be captured, but static HTML content (which covers most documentation, articles, and reference pages) will work correctly.

Interactively review PR in Roo Code Cloud

When users paste a URL via the @url context menu option, the URL content
is now actually fetched using axios+cheerio instead of just inserting a
quoted reference. This was broken after the browser feature was removed.

- Add fetchUrlContent utility using axios for HTTP and cheerio for HTML
  text extraction
- Add URL mention handling in parseMentions() to fetch and include
  content as a MentionContentBlock
- Add comprehensive tests for both the utility and integration

Closes #11856
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] contextMenu.url not work

1 participant