3

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?

aj93
  • 83
  • 2
  • 7
  • Does this answer your question? [window.close and self.close do not close the window in Chrome](https://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome) – Bahador Raghibizadeh Dec 25 '19 at 10:34
  • Extension can quit the browser by enumerating all windows and closing them, see chrome.windows API. However a better solution might be for you to use Puppeteer to automate whatever you do instead of an extension. – wOxxOm Dec 25 '19 at 10:38

1 Answers1

2

Closing every tab would close the window in Google Chrome.

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

});
keser
  • 2,472
  • 1
  • 12
  • 38