Chrome removes the function that I’m trying to pass through sendRequest.
function sendQuery() {
var currentQuery = document.getElementById("queries").value;
var request = {
option: "random value",
command: function() {
alert("fire!");
}
};
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, request)
});
}
As you can see, request contains function command, but when I ‘dump’ the request that was received by contentscript, everything I get is this:
request
Object
option: "random value"
__proto__: Object
I need to pass the command as well, not just the option. Thanks in advance for helping me to do so.
Edit: Edited according to Pointy’s suggestion, but the problem remains.
The second parameter of
chrome.tabs.sendRequestis JSON serialized for transportation.The one and only way to pass a function is via the third parameter. This function is received as a third parameter at the
chrome.extension.onRequestevent listener: