I'm trying to close the Options page of the extension. I have a Cancel button and I'm using this code:
chrome.tabs.getCurrent(null, function(tab) { chrome.tabs.remove(tab.id, function() {}); });
When I'm trying to use it, it always gives this error:
Uncaught TypeError: Cannot call method 'getCurrent' of undefined
What's wrong with the code?
Chrome: Select Settings > On startup > Open the New Tab page. Edge: Select X > Close All and check Always close all tabs. Android Chrome/Firefox: Select Tab > three dots > Close all tabs.
The Window. close() method closes the current window, or the window on which it was called. This method can only be called on windows that were opened by a script using the Window. open() method.
It works for me with one little fix:
chrome.tabs.getCurrent(function(tab) { chrome.tabs.remove(tab.id, function() { }); });
Just make sure you're really running this code in options page of your extension and not just some HTML page, because chrome.tabs API is available only for extensions.
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