1

I was trying to figure out how to make a chrome extension (new to experimenting with this) that would automatically close a tab if the URL contained a specified string, but everything I've read says you can't do that in javascript - trying to do so with window.close() just generates the error message "VM145:1 Scripts may close only the windows that were opened by it."

However, I've just found out that an extension exists that will do exactly what I wanted to do (tested - works on the latest version of Chrome), called "Ad Close Gold" - how could this be working if Javascript can't close tabs?

  • Javascript (on a website) has very limited access to your browser and no access to the clients computer outside of the browser at all. That's why it cannot close tabs that it doesn't "own". So if JS opened up a tab, it's the "owner" of it and therefor allowed to close it. Browser extensions are a different story. They have more access to the browser and the users pc, although still limited for security reasons. That is why `chrome.tabs.remove(tabId)` would allow you to close a tab in a browser extension. However, normal JS like `window.close()` is still bound to the limitations of it. – icecub Mar 10 '19 at 22:56
  • Gotcha - Thanks! – Ian McKenzie Mar 12 '19 at 04:05

0 Answers0