Browser’s extensions to allow web client bypass CORS limit.
See the full architecture guide first.
cd extension && pnpm installto install dependencies.cd extension &&pnpm start` to run the plugin in development mode.cd extension && pnpm buildto build the plugin for production.
-
Run
cd extension && pnpm startto build the extension and watch the changes. -
Open
chrome://extensions/→Load unpackedand choosedistfolder from this repo. The extension should appear in the list of your extensions. -
In the
.envfile of the main app, place the next line (EXTENSION_IDcan be found in theIDline 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 buildto 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_IDof the published extension as a prod env for the web app.