Route API requests through background to bypass host-page CSP#189
Route API requests through background to bypass host-page CSP#189
Conversation
Co-authored-by: rosscado <16578183+rosscado@users.noreply.github.com>
Co-authored-by: rosscado <16578183+rosscado@users.noreply.github.com>
|
@cursoragent , can you please review this PR? |
|
I started by scanning the repository for the new serializer, background handler, and Overall, I found the approach to routing SayPi API calls through the background worker to be solid and cleanly implemented, maintaining the However, I identified a few blocking issues that need to be addressed, including an attempt to override the read-only Learn more about Cursor Agents |
…requests Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
…andling Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
… handling Co-authored-by: ross.cadogan <ross.cadogan@gmail.com>
rosscado
left a comment
There was a problem hiding this comment.
This is working well across both Chrome and Firefox, and is good to merge.
There are still some issues with Google Gemini on Firefox, which is the site which initially prompted this. feature request. However, that issue is unrelated to the proxying of API calls.
Some host pages (e.g.,
gemini.google.com) enforce restrictive Content Security Policy (connect-src) that blocks network requests from the page realm tohttps://api.saypi.aiandhttps://www.saypi.ai. This breaks critical extension functionality including audio transcription uploads, authentication token refresh, and voice synthesis requests.This PR implements a solution that routes SayPi API requests through the extension's background service worker to bypass CSP restrictions while maintaining full backward compatibility.
Key Changes
1. ApiRequestSerializer utility (
src/utils/ApiRequestSerializer.ts)Handles serialization/deserialization of API requests for transmission between content scripts and background service worker:
FormDataandBlobobjects that cannot be directly passed throughchrome.runtime.sendMessageArrayBufferfor structured clone compatibility2. Background API handler (
src/svc/background.ts)Extends the existing background service worker with an
API_REQUESTmessage handler:JwtManager3. Smart routing in ApiClient (
src/ApiClient.ts)Modified
callApifunction to intelligently route requests:Implementation Highlights
callApiinterfaceTesting
Added comprehensive unit tests covering:
The implementation successfully bypasses CSP restrictions on restrictive sites while maintaining full functionality on all existing sites.
Fixes #188.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.saypi.ainode (vitest 1)(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.