3

I'm trying to find a way to detect when the user closes or dismisses the pop-up in an iOS Safari web extension.

I've tried listening for onblur, pagehide, and visibilitychange events but they are not fired when the popup is closed. All of these events do fire on macOS Safari 16, though.

Opening up a port by running browser.runtime.connect() in the popup and listening for onConnect/onDisconnect events in the background script only causes the onConnect event to fire when the popup is opened.

Harrison Friia
  • 372
  • 2
  • 10

2 Answers2

0

I stumped over the same problem and discovered, that the visibility change event get only fired when:

  • Visible
  • Page reload

On page reload the hidden gets fired. But I need to get it when the popup is closed.

Looks like this is a bug but workarounds are welcome.

Matt
  • 448
  • 5
  • 16
0

The best solution I found was listening for the blur event. It seems to be fired only when the pop up is closed, but only if the user first taps somewhere inside the popup.

Harrison Friia
  • 372
  • 2
  • 10