Safari 5.0 extension API and window.close()
Tuesday, July 06, 2010
I wanted to make a quick note about how safari.application.openBrowserWindow().activeTab and window.close() result in a lack of interaction.
Backstory
In a nutshell, window.close() isn’t allowed to close a window for a document that wasn’t created via Javascript. The idea is that a script shouldn’t be able to willy nilly start ruining your browsing experience by closing a browser window that you’ve, until right now, built up a web page history; a window.close() at that point would remove your browser window and leave you with no back button to get to where you’ve been. There are other ramifications, I guess, but for me that’s the most obvious one.
Fast Forward to Safari 5.0
So I forked the delicious safari extension, from Jeveaux’s original repo, and made a few changes to enhance it. One of my updates was to include an option to allow Delicious to open in a new window as well as a new tab. A week later I decided to look into why the window wasn’t closing on the Delicious page after you’ve saved it.
Inspecting the source of Delicious’ post-save page you’ll see that it has a simple window.close() in the head. So why does it not work? It’s a window opened with javascript right?
My suspicion is that, because it hasn’t been opened with window.open(), it is classed as a standard window. My next task for the Delicious Safari Extension is to switch it over to window.open() and then I’m going to file a report/bug/feature request to see if Safari can weigh in on it and perhaps make some small changes for us.
Update: I've got a bug report filed 8165625: Safari 5 extension API and window.close() so here's hoping that it gets some attention
Update 2: I finally found the reference to where it mentions that you can't use window.open() within the API docs. Just for people who are asking me to use window.open() as an interim solution.
Comments