Search code examples
javascriptgoogle-chrome-extensioncron

How to close the Chrome browser automatically after a certain condition?


I wrote a Web Extension which starts surfing specified websites automatically after the Chrome browser is opened.

As far as i know Javascript doesn't allow closing the Chrome browser easily.

(window.open => window.close didn't work for me.)

My cronjob will start/open Chrome at certain times and allow the Web Extension to work.

I guess that after some time too many Chrome browsers will be open, so i would like to close them.

Either after the website surfing is complete (there is a certain condition) or after like 30 minutes.

Are there any options?


Solution

  • Closing every tab would close the window in Google Chrome.

        chrome.tabs.query({}, function (tabs) {
        tabs.forEach(tab => {
            chrome.tabs.remove(tab.id, function() { });
        });
    
    });