Skip to content

feat(ai): add port-based streaming to bypass CORS in content scripts#46

Open
PinkChampagne17 wants to merge 1 commit into
yusixian:devfrom
PinkChampagne17:feat/cors-bypass-streaming
Open

feat(ai): add port-based streaming to bypass CORS in content scripts#46
PinkChampagne17 wants to merge 1 commit into
yusixian:devfrom
PinkChampagne17:feat/cors-bypass-streaming

Conversation

@PinkChampagne17
Copy link
Copy Markdown

@PinkChampagne17 PinkChampagne17 commented Mar 9, 2026

Summary

  • Content scripts run in the webpage's origin, causing CORS failures for direct AI API calls
  • Add a port-based streaming relay through the background script (background/ports/aiStream.ts)
  • Add usePortStream hook for client-side port streaming consumption
  • Integrate port streaming path in useAiSummary with automatic content script detection

Test plan

  • Load extension in Chrome, open floating popup on any webpage
  • Trigger AI summary — verify streaming output works via port relay
  • Check that popup/sidepanel AI summary still works (non-content-script path)
  • Verify port disconnect properly rejects pending promises

🤖 Generated with Claude Code

Direct fetch calls from content scripts fail due to CORS. Relay AI
streaming through background port messaging to preserve streaming
UX while avoiding cross-origin restrictions.

- background/ports/aiStream.ts: streaming relay handler
- hooks/usePortStream.ts: client-side port stream hook
- hooks/useAiSummary.ts: auto-detect content script context

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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