Skip to content

feat: include page URL in copied context#272

Open
sour4bh wants to merge 2 commits intoaidenybai:mainfrom
sour4bh:feat/include-url-in-copy
Open

feat: include page URL in copied context#272
sour4bh wants to merge 2 commits intoaidenybai:mainfrom
sour4bh:feat/include-url-in-copy

Conversation

@sour4bh
Copy link
Copy Markdown

@sour4bh sour4bh commented Mar 29, 2026

Summary

  • Appends the current page URL as a URL: <href> footer in text/plain and text/html clipboard output when grabbing elements, giving AI tools immediate context about where the element was found
  • Adds a structured url field to the application/x-react-grab clipboard metadata for programmatic access
  • Only the primary grab path appends the URL text footer; comment re-copy and plugin copies (styles, HTML) omit it but still record the URL in metadata

Design decisions

  • URL footer is opt-in via copyContent() options — only callers that pass url get the text footer appended. This keeps copy-styles (CSS) and copy-html (raw HTML) output clean.
  • metadata.content stays clean — no URL text embedded. Consumers use metadata.url for structured access, avoiding redundancy.
  • URL is read once per copy operation in copy.ts and passed through to copyContent(), with a window.location.href fallback in copyContent() for paths that don't pass it explicitly (ensuring metadata.url is always populated).

Test plan

  • New copy-url.spec.ts with 5 tests: single element, URL ordering, metadata structure, copy with comment, multi-element drag
  • Updated element-context.spec.ts truncation test to assert on snippet portion only (before URL footer)
  • All 584 existing e2e tests pass
  • TypeScript typecheck passes
  • Linter passes (0 warnings, 0 errors)

Summary by cubic

Include the current page URL in copied content so snippets carry their source. Adds a structured URL field to clipboard metadata and appends a text footer for primary and comment copies.

  • New Features

    • Appends "URL: " to text/plain and text/html for primary and comment copies; plugin copies (styles, HTML) omit the footer.
    • Adds url to application/x-react-grab metadata; metadata.content stays unchanged.
    • Footer is opt-in via copyContent({ url }); metadata always includes a URL via window.location.href fallback.
  • Bug Fixes

    • Aligned onCopySuccess to pass the actual clipboard text (including the URL footer) to plugins.

Written for commit ed1ed8f. Summary will update on new commits.

Appends the current page URL to clipboard text when grabbing elements,
giving AI tools and collaborators immediate context about where the
element was found. The URL appears as a footer in text/plain and
text/html clipboard output, while structured metadata exposes it via
a dedicated `url` field on the `application/x-react-grab` payload.

- Primary grab copies append `URL: <href>` after the snippet
- Comment re-copy and plugin copies (styles, HTML) omit the text
  footer but still record the URL in metadata
- `metadata.content` stays clean (no URL text); consumers use
  `metadata.url` for structured access
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 29, 2026

@sour4bh is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34c963349f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 78 to +81
didCopy = copyContent(copiedContent, {
componentName: options.componentName,
entries,
url,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep onCopySuccess content aligned with clipboard payload

Passing url into copyContent here makes the actual clipboard text include a URL: ... footer, but tryCopyWithFallback still reports copiedContent (without that footer) to onCopySuccess later in the same function. In environments where plugins use onCopySuccess to forward or diff what was copied, this creates a behavior mismatch and drops the new URL context from hook consumers even though users copied it to the clipboard.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

addressed

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

@sour4bh
Copy link
Copy Markdown
Author

sour4bh commented Mar 29, 2026

@aidenybai commented throughout my app across multiple pages, when i dropped in the copied context, the comments lost localized context especially when you have composite components across multiple pages.

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.

1 participant