U
U
Uno2017-07-22 05:56:08
JavaScript
Uno, 2017-07-22 05:56:08

How to open and close a tab after a few seconds?

Good afternoon. Due to the undocumented chrome extensions api and incomplete education on subtle JS issues, I can’t open and close the tab after a few seconds after opening it.
I've already tried everything, it doesn't work out, and dug the docks, and Google - not a single normal explanation of what exactly I'm doing wrong.
Of course, before closing it, you need to execute a script on it and talk to it, but I’ll more or less figure it out, but I have no idea how to close it.
Please help!

chrome.tabs.create({active: true, url: "https://facebook.com"});
chrome.tabs.onUpdated.addListener(function (){
    chrome.tabs.query({active: true}, function (alltabs){
        ...
        setTimeout(function (){chrome.tabs.remove(alltabs[0].id)}, 3000);
    });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-07-22
@Noizefan

You can close the current tab like this

chrome.tabs.getCurrent(function(tab) {
    chrome.tabs.remove(tab.id, function() { });
});

Don't forget to add access to https://developer.chrome.com/extensions/tabs in your manifest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question