How do you detect Private Browsing access setting change?

I would like to detect when the user grants or denies the add-on permission to run in Private Browsing mode. When I had the add-on loaded as a temporary add-on, it worked out that I could just use the runtime install handler to listen for when the add-on is updated and when the previous version matches the version in the manifest. Something like this in the background.js file:

function handleInstalled(details) {
    if (details.reason == 'update' && browser.runtime.getManifest().version == details.previousVersion) {
        // Do something
    }
}
browser.runtime.onInstalled.addListener(handleInstalled);

However, as it turns out, that doesn’t work in release.

My main motivation behind wanting to do this is because it breaks a first run page.

For example, if I want the add-on to open a welcome message in a new tab on install, if the user grants access to Private Browsing using the checkbox on the add-on install popup that Firefox currently displays in the top-right corner, that first run page is closed and there’s no way to open it back up.

That only occurs when the welcome page is an HTML file that’s bundled with the add-on, such as the options page for the add-on.

Any idea if there’s a work around for this issue? To be honest, it kind of seems like a bug that could be addressed by the Firefox devs.

Interesting!
I’m pretty sure granting Private Browsing will reload extension which closes all extension pages.

But in production you could use storage to remember if the welcome page was displayed and closed by user.