I am trying to remove the onRequest listener added by chrome.extension.onRequest.addListener after a request is made, like this:
chrome.extension.onRequest.addListener(
function(request){
chrome.extension.onRequest.removeListener();
other_function(request);
}
);
The problem is that I don’t know if this works or not. I tried chrome.extension.onRequest.hasListener, which seems not to give the right answer, so I am wondering if there are some other ways to remove the onRequest listener or check if the listener exists or not.
Thanks!
removeListenertakes an argument. You need to name the listener function and then remove it by name:Or, more succinctly: