Securely sending message from a react app to a chrome extension

72 views Asked by At

I have a chrome extension with manifest.json, but in order to be used, a user needs to be authenticated. If an unauthenticated user clicks the extension icon, they are redirected to a login (react) page. On successful login i want the react page to securely pass the info (login token) to the extension that the user is now authenticated. How can i go about this; to pass the sensitive token from the react to the extension. I am using MV3 in my extension

in my app.tsx below

if (session) {
      const token = session.getToken();
      chrome.runtime.sendMessage({ type: 'setToken', data: token }, (res) => {
        // ...
        
      });
    }

I cannot use the chrome.runtime as above (Cannot read properties of undefined (reading 'sendMessage')) since i do not have the Chrome extension APIs in my react app

0

There are 0 answers