0

We created extensions for Chrome, Firefox and Safari. We want to open a new tab when uninstalling our extension. I found this code for Chrome, but is it possible to do it in Safari and Firefox?

switch (platform) {
    case 'chrome':
        try {
            chrome.runtime.setUninstallURL(uninstall_url);
        } catch(e) {
            console.error(e);
        }
        break;
}
Uri
  • 2,992
  • 8
  • 43
  • 86

2 Answers2

2

In place of manifest.json Safari extensions use Info.plist which is typically generated with ExtensionBuilder. As you can see from the provided screenshot, no 'uninstallURL' is available. I suggest testing a beforeUnload listener in the global page but this will probably also be triggered during other events like updates, browser closing etc.

As for Firefox, it all depends on the actual API your add-on is based on. You maybe out of luck if you have used the Addon SDK or created a legacy XUL overlay extension. However, Restartless bootstrapped extensions use low-level APIs and the uninstall function in bootstrap.js receives a reason parameter:

function uninstall(data, reason) {
    if (reason === ADDON_UNINSTALL) {
        let win = Services.wm.getMostRecentWindow('navigator:browser');
        win.gBrowser.selectedTab = win.gBrowser.addTab(url);
    }
}

Good news is a new WebExtensions API is coming to Firefox. It is basically identical to the Chrome API. See the relevant bug

minj
  • 2,080
  • 12
  • 10
2

From addon sdk you would use this https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload

That shows you how to listen for load and unload and detect the reason for load/unload solution is from here - https://stackoverflow.com/a/31497334/1828637

Community
  • 1
  • 1
Noitidart
  • 35,443
  • 37
  • 154
  • 323