Closed Bug 1172928 Opened 5 years ago Closed 5 years ago

Window.close() does not close the tab


(Firefox for iOS :: General, defect)

Not set



Tracking Status
fxios + ---


(Reporter: st3fan, Assigned: st3fan)



(Whiteboard: ios9, needs-cleanup)


(1 file, 1 obsolete file)

This is a followup bug for 1124942, which has not landed yet.


* Go to
* Login with persona
* The Persona login screen should appear in a new tab
* Finish the login


The persona login tab closes and you go back to the tab you came from.


Persona just sits there. But if you manually close the tab and you go back to the tab, you are actually correctly logged in.

Not sure what piece we miss to support window.close(), may be some WKWebView delegate that we need to implement?
Assignee: nobody → jhugman
It looks like that there is no public API for detecting window.close events in WKWebview frameworks.

There is some code in Webkit demonstrating a private API, but this doesn't seem to be working for us in Swift. Plus: private APIs.
The bug that I filed yesterday was closed as a dupe of which adds a webViewDidClose: delegate method to the WKUIDelegate. So that will allow us to do this without any JavaScript hacks.

What I would like to suggest is that we do a simple solution now, like patching window.close(), which will probably catch 75% of the use-cases. And then replace that JavaScript solution with the new WKUIDelegate when we are ready for iOS9 later this year.
Flags: needinfo?(jhugman)
One-line fix in iOS 9. Let's punt this to 2.0.
Whiteboard: ios9
Summary: Persona login (popup) window does not close after logging in → Window.close() does not close the tab
Work in progress but please take a look anyway. This may catch most cases. Except persona as noted below.

This patches window.close to send us a callback so that the native code can close the tab. This work for the general case. It does not work for Persona because Persona is insanely complicated and they probably do something special.
Assignee: jhugman → sarentz
Attachment #8629164 - Attachment is obsolete: true
Attachment #8634771 - Flags: review?(bnicholson)
Flags: needinfo?(jhugman)
Comment on attachment 8634771 [details] [review]

LGTM with a few comments.
Attachment #8634771 - Flags: review?(bnicholson) → review+
Couple of notes:

This works correctly on for example which opens a new tab with a Facebook login. After logging in the tab closes correctly and you are back at the original tab and logged in.

On Persona this fails, but now I think this may not be an error in this code but an issue with Persona. I see a message about origin not matching (This appears in the console for - dont forget to attach the debugger to the right tab)
Assignee: sarentz → jhugman
See Also: → 1186030
Assuming we want to land this since it handles some cases on iOS 8. Filed bug 1186030 for iOS 9 specifically.
Assignee: jhugman → nobody
Whiteboard: ios9 → ios9, needs-cleanup
Assignee: nobody → bmunar
Assignee: bmunar → administration
Assignee: administration → nobody
Stefan, this needs landing.
Assignee: nobody → sarentz
I'll deal with the review comments on tuesday and land it then.

Is there someone on the (old) Persona team who we can loop in to see if we can find out why this patch does not work for the Persona popup? Persona does crazy things, but I don't know enough about JS to understand what specifically.
Flags: needinfo?(rnewman)
I have addressed the review comments and landed this. Couple of notes:

 * There is a test page at that shows this fix in action.
 * For testing it is important to know that WebKit only lets you window.close() webviews that have a parent/child relationship. You can't just window.close() any window.
 * This does not work with Persona yet because I assume Persona does some more complicated things. I have reached out to people to get that fixed too, which can be done as a followup bug.
Flags: needinfo?(rnewman)
Closed: 5 years ago
Resolution: --- → FIXED
Shane Tomlinson would be your best bet from the legacy Persona team. You might want to approach Ryan Kelly or Chris Karlof about getting some of Shane's time to look into this.
Look like this issue is produce again in latest build.

Please have a look into this issue for more detail.

I also did pull request for solution

Here is a test url i created to test.
Flags: needinfo?(sarentz)
Please file a new bug.
Flags: needinfo?(sarentz)
You need to log in before you can comment on or make changes to this bug.