author Santo Pfingsten
 *  see https import { browser , Tabs } from "webextension-polyfill-ts" ; import { DEFAULT_COOKIE_STORE_ID } from "../shared" ; export class IncognitoWatcher { private cookieStores = new Set < string > ( ) ; private tabs = new Set < number > ( ) ; public constructor ( ) { this . onCreated = this . onCreated . bind ( this ) ; this . onRemoved = this . onRemoved . bind ( this ) ; browser . tabs . query ( { } ) . then ( ( tabs ) => tabs . forEach ( this . onCreated ) ) ; browser . tabs . onRemoved . addListener ( this . onRemoved ) ; browser . tabs . onCreated . addListener ( this . onCreated ) ; } private onCreated ( tab ) { if ( tab . id && tab . incognito ) { this . tabs . add ( tab . id ) ; this . cookieStores . add ( tab . cookieStoreId || DEFAULT_COOKIE_STORE_ID ) ; } } private onRemoved ( tabId , removeInfo ) { this . tabs . delete ( tabId ) ; } public hasCookieStore ( cookieStoreId ) { return this . cookieStores . has ( cookieStoreId ) ; } public hasTab ( tabId ) { return this . tabs . has ( tabId ) ; } public forceAdd ( tabId , cookieStoreId ) { this . tabs . add ( tabId ) ; this . cookieStores . add ( cookieStoreId ) ; } public forceDelete ( tabId , cookieStoreId ) { this . tabs . delete ( tabId ) ; this . cookieStores . delete ( cookieStoreId ) ; } }