Exit popup

67 views
Skip to first unread message

Mark

unread,
Nov 3, 2010, 4:16:55 AM11/3/10
to Chromium-extensions
Is there anyway to make the browser action popup go away with
JavaScript while using it, i.e. form submitting?

PhistucK

unread,
Nov 3, 2010, 4:27:32 AM11/3/10
to Mark, Chromium-extensions
window.close();

PhistucK



On Wed, Nov 3, 2010 at 10:16, Mark <dlo...@gmail.com> wrote:
Is there anyway to make the browser action popup go away with
JavaScript while using it, i.e. form submitting?

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Anastasia

unread,
Nov 3, 2010, 11:27:59 AM11/3/10
to Chromium-extensions
If you mean you want to close the pop-up while an AJAX call (or
something similar) is still in progress from the popup itself, the
answer is that you can't. Closing the popup with something like
window.close() (or just clicking away from it) terminates its
connections without resolving them. The generally accepted work-
around is to have the AJAX call (or form submission or whatever)
happen in your background page and to send the data you want to submit
using sendRequest. Once you've sent the data to the background page
you can close the popup and since background is still open it will
keep all of its connections.

If that's not what you were asking, well, maybe it'll help someone
anyway,
Ana

Johan Sundström

unread,
Dec 20, 2010, 8:57:45 PM12/20/10
to Anastasia, Chromium-extensions
On Wed, Nov 3, 2010 at 08:27, Anastasia <rushi...@gmail.com> wrote:
If you mean you want to close the pop-up while an AJAX call (or
something similar) is still in progress from the popup itself, the
answer is that you can't.  Closing the popup with something like
window.close() (or just clicking away from it) terminates its
connections without resolving them.  The generally accepted work-
around is to have the AJAX call (or form submission or whatever)
happen in your background page and to send the data you want to submit
using sendRequest.  Once you've sent the data to the background page
you can close the popup and since background is still open it will
keep all of its connections.

I have this use case in an extension I'm working on, and changed to make the window.close() call happen immediately after the postMessage to my background page. While this seems to work well in the Chrome versions I have tested, are all messages I've posted to the background page guaranteed to get processed, or is there any risk that the window.close kills the execution context and any unfinished business it had in its event loop, like outbound messaging that should get processed?

--
 / Johan Sundström, http://ecmanaut.blogspot.com/

Antony Sargent

unread,
Dec 21, 2010, 2:44:37 PM12/21/10
to Johan Sundström, Anastasia, Chromium-extensions
It's probably ok, But to be really sure, you could send an "ack" message from the background page and only do the window.close when you've received it in the popup. 

Johan Sundström

unread,
Dec 22, 2010, 2:13:00 PM12/22/10
to Antony Sargent, Anastasia, Chromium-extensions
2010/12/21 Antony Sargent <asar...@chromium.org>

It's probably ok, But to be really sure, you could send an "ack" message from the background page and only do the window.close when you've received it in the popup. 

No; that's the thing – if you defer the window.close to *any* kind of later callback (be it via a setTimeout, or an onmessage handler waiting for that "ack" ping) that makes the window.close happen in an execution context that was not directly initiated by a user action, window.close will fail to close the window.

That is at least my take on it, after having done some heavy testing about which conditions make window.close fail when it seemingly shouldn't. If you have anything more concrete about what can be done to have a message handler waiting for the ack not lose window.close privileges, I would be very interested, though. It at least fails on Chrome 9.

Which is why I want to be sure there is a guarantee that postMessage calls do happen, whether the window was closed immediately after they were scheduled: there is no way for the script code itself to verify that yes, it went through; you only have one attempt to close it, and can't wait until after you verified that it (whatever) happened.

(In my case, it's not an extension popup, but an html dialog opened by window.open from the background page right after initial install time, asking whether the user wants to opt in to a feature, with "yes, please" and "no, thanks" buttons, each of which report back to the background page that stores the choice in localStorage – and I want to be sure we never bug the user by asking twice.)

Antony Sargent

unread,
Dec 22, 2010, 4:59:47 PM12/22/10
to Johan Sundström, Anastasia, Chromium-extensions
Ah, you're right. That's a bug that window.close doesn't work in the popup - I've created crbug.com/67842 to track it. 
Reply all
Reply to author
Forward
0 new messages