How do I call this from background.js?
Opened this issue · 2 comments
The main.js is working as it calls gmail.get.user_email() fine. However, I want to do something when the icon is clicked. I added a background.js that has chrome.browserAction.onClicked.addListener and it gets called but I cannot access the gmail object.
Do I have to enable something for this? Am somewhat new to extensions so I feel like I am missing a step.
Thanks for any tips or pointers.
@ConnGator One approach that might be useful is sending a message from background.js to your main.js, and having a listener in your main (chrome.runtime.onMessage.addListener) that does what you want when it receives that message.
As far as having to enable anything, assuming you are doing something within the active tab, I believe you need the "activeTab" permission in your manifest.json.
@hemmendinger @ConnGator I'm trying to get chrome extension options using chrome.storage.sync
from within my main.js
but cannot access the same chrome
object as the content script. The main.js
chrome object does not have the same functionality as the one in content.js
.
I figured that a way round this was messaging between the scripts but cannot get that working.
If anyone has a working example of passing messages between main.js
and content.js
within the context of this boilerplate that would be great.