Is there a way to call a function in the background script from the popup? I can't explain it much further than that question. It's not an error I'm having with what I'm trying to do but rather something I completely don't know how to do. I want to make it possible to click a button in the popup page that'll call a function defined in the background page.
It is indeed possible, using Message Passing.
popup.js
$("#button").click(function(){
chrome.runtime.sendMessage({ msg: "startFunc" });
});
background.js
var func = function(){
alert("Success!");
};
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
if(request.msg == "startFunc") func();
}
);
Try this
var bgPage = chrome.extension.getBackgroundPage();
var dat = bgPage.paste(); // Here paste() is a function that returns value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With