GoogleChrome / chrome-extensions-samples

Chrome Extensions Samples
https://developer.chrome.com/docs/extensions
Apache License 2.0
15.47k stars 8.23k forks source link

Sample: transfer data (sensitive api) from background to popup #774

Open hyfydistro opened 2 years ago

hyfydistro commented 2 years ago

Currently, I'm unable to access the Chrome Extension Group so I will post here.

I'm just wondering if anyone knows how to grab data from the service worker (background script) and receive it at the popup page. I am using airtable and it has some sensitive information for the configuration I don't want to leak out so I have it setup in my background script. I just want to transfer certain data and display it on the client safely.

Is there any available examples?

guest271314 commented 1 year ago

I just want to transfer certain data and display it on the client safely.

How are you defining "safely"?

You can use messaging to send data to and from ServiceWorker from content script.

Hanaffi commented 8 months ago

@patrickkettner @AmySteam can you assign it to me please?

oliverdunk commented 8 months ago

@Hanaffi, could you share some more about what you are proposing for a sample?

Hanaffi commented 8 months ago

@oliverdunk we can do message passing using chrome.tabs.sendMessage and listening for it on the other side. We can also do asymmetric encryption of the message but I think it would be an overkill because I think this message passing API is safe enough, thoughts?

Hanaffi commented 8 months ago

@oliverdunk ?

oliverdunk commented 8 months ago

Agreed that encryption would be too much here. We already have an Action API demo. Perhaps you could update that with some simple functionality where the popup gets some data by messaging the background?