Browser’s extensions to allow web client bypass CORS limit.
See the full architecture guide first.
cd extension && pnpm install
to install dependencies.cd extension &&
pnpm start` to run the plugin in development mode.cd extension && pnpm build
to build the plugin for production.
-
Run
cd extension && pnpm start
to build the extension and watch the changes. -
Open
chrome://extensions/
→Load unpacked
and choosedist
folder from this repo. The extension should appear in the list of your extensions. -
In the
.env
file of the main app, place the next line (EXTENSION_ID
can be found in theID
line inside the uploaded extension block):VITE_EXTENSION_ID=EXTENSION_ID
-
Run the web client.
During the development process, you can re-build the extension by clicking on the update button at the right bottom of the extension’s block.
You can see the console for errors and logs by clicking on the link at the line Inspect views: service worker
in the extension’s block.
Connect the extension on application start:
let port = chrome.runtime.connect(import.meta.env.VITE_EXTENSION_ID)
Send messages to the extension to fetch data:
port.postMessage({
url: 'https://example-url',
options: { method: 'GET' }
})
port.onMessage.addListener(response => {
console.log(response.data) // The extension will send the message
})
Check if the extension was disconnected:
port.onDisconnect.addListener(() => {})
See possible messages in types API.
- Run
pnpm build
to build the production files (will be located indist/
) - Zip the content of the
dist/
folder - Follow official guide to publish the extension in the Chrome Web Store.
- After the extension is published in the Chrome Web Store, add the
EXTENSION_ID
of the published extension as a prod env for the web app.