popup onunload or onbeforeunload

2,332 views
Skip to first unread message

loosedog

unread,
Apr 4, 2010, 12:18:50 AM4/4/10
to Chromium-extensions
I'm writing a google chrome extension with a popup and a background
page. The popup subscribes to certain events that the background
generates, and I would like to unsubscribe from those events when the
popup goes away. However, I don't see either of onbeforeunload or
onunload events being generated from the popup. Are these events
fired? If not, any ideas on how to capture popup close?

Antony Sargent

unread,
Apr 6, 2010, 5:50:03 PM4/6/10
to loosedog, Chromium-extensions
This feature request would address your needs I think:


You can star the bug to get updates on it. In the comments there I noted a hacky workaround (polling from the background page) that you could use in the mean time.



--
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.


Antony Sargent

unread,
Apr 6, 2010, 5:55:55 PM4/6/10
to loosedog, Chromium-extensions
Actually for your case, there are two approaches you might take:

1) Use the messaging APIs to set up a Port between the popup and background page. You then should get a onDisconnect event in the background page when the popup goes away.

2) Have the background dispatch events using chrome.extension.getViews() - if there is a popup in the list, you use the DOMWindow handle to call a function in the popup directly.

loosedog

unread,
Apr 11, 2010, 2:26:10 PM4/11/10
to Chromium-extensions
Your #1 suggestion worked out pretty well in my case. Since my popup
was registering itself as an observer I added a special addObserver
method that stored a reference to the popup's observer. Then I opened
a port from the popup. The background page registered the port and
sets up an onDisconnect that removes the popup's observer.

So I'll keep my eyes on that unload ticket but for now this
works...thanks.

On Apr 6, 2:55 pm, Antony Sargent <asarg...@chromium.org> wrote:
> Actually for your case, there are two approaches you might take:
>
> 1) Use the messaging APIs to set up a Port between the popup and background
> page. You then should get a onDisconnect event in the background page when
> the popup goes away.
>
> 2) Have the background dispatch events using chrome.extension.getViews() -
> if there is a popup in the list, you use the DOMWindow handle to call a
> function in the popup directly.
>

> On Tue, Apr 6, 2010 at 2:50 PM, Antony Sargent <asarg...@chromium.org>wrote:
>
>
>
> > This feature request would address your needs I think:
>
> >http://crbug.com/31262
>
> > You can star the bug to get updates on it. In the comments there I noted a
> > hacky workaround (polling from the background page) that you could use in
> > the mean time.
>

> > On Sat, Apr 3, 2010 at 9:18 PM, loosedog <loose...@gmail.com> wrote:
>
> >> I'm writing a google chrome extension with a popup and a background
> >> page. The popup subscribes to certain events that the background
> >> generates, and I would like to unsubscribe from those events when the
> >> popup goes away. However, I don't see either of onbeforeunload or
> >> onunload events being generated from the popup. Are these events
> >> fired? If not, any ideas on how to capture popup close?
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Chromium-extensions" group.

> >> To post to this group, send email to chromium-extensi...@chromium.org.


> >> To unsubscribe from this group, send email to

> >> chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>

Reply all
Reply to author
Forward
0 new messages