The issue is that when I invoke
doesn't close the window. Now there seems to be a belief that in Chrome you can't close by script any window that is not script created. That is patently false but regardless it is supposed to still do it, even if it requires to pop up an alert to confirm.
These are not happening.
So does anyone have real, functional and proven method of closing a window using something like
latest working spec for
on Window objects should, if all the following conditions are met, close the browsing context A:
The corresponding browsing context A is script-closable.
The browsing context of the incumbent script is familiar with the browsing context A.
The browsing context of the incumbent script is allowed to navigate the browsing context A.
A browsing context is script-closable if it is an auxiliary browsing context that was
created by a script(as opposed to by an action of the user), or if it is a browsing context whose session history contains only one Document.
Chrome allows that exception -- which it doesn't apply to userscripts -- however Firefox does not. The
Firefox implementation flat out states:
This method is only allowed to be called for windows that were opened by a script using the
If you try to use
a Greasemonkey / Tampermonkey / userscript you will get:
Firefox: The error message, "
may not close windows that were not opened by script."
Chrome: just silently fails.
The long-term solution:
The best way to deal with this is to make a Chrome extension and/or Firefox add-on instead. These can reliably close the current window.
However, since the security risks, posed by
are much less for a Greasemonkey/Tampermonkey script; Greasemonkey and Tampermonkey could reasonably provide this functionality in their API (essentially packaging the extension work for you).
Consider making a feature request.
The hacky workarounds:
Chrome is currently vulnerable to the "self redirection" exploit. So code like this will currently work
in Tampermonkey scripts:
This is buggy behavior, IMO, and is liable to be blocked by future releases of Chrome, so use this hack with that in mind.
You can open up
If your script is for personal use, go ahead and do that. If you ask anyone else to turn that setting on, they would be smart, and justified, to decline with prejudice.
There currently is no equivalent setting for Chrome.
From my observation, this update fixed the issue on using
close the popup window. You will see this in the console when it fail, "Scripts may close only the windows that were opened by it.". That means The
hacky workarounds (Brock Adams's answer) may not work in the latest release.
So, in the previous Chrome released builds, the below code block may worked but not with this update.
window.open('', '_self', '');
For this update, you have to update your code accordingly to close the popup window. One of the solution is to grab the popup window id and use
chrome.windows.remove(integer windowId, function callback)
method to remove it. Chrome extension windows API can be found at chrome.windows.
Actually my chrome extension MarkView was
facing this issue and I had to update my code to make it work for this Chrome Update. By the way, MarkView is tool to read and write Awesome Markdown Files, it provides features including Content Outline, Sortable Tables and code block syntax highlight with
I also created this
post, any comments are welcome.
I use top.close() to
close a tab. window.close() or
other open...close didn't work for me.