author Santo Pfingsten
 *  see https import { browser , WebRequest , WebNavigation } from "webextension-polyfill-ts" ; import { getValidHostname } from "../shared" ; const WEB_REQUEST_FILTER = { urls : [ "<all_urls>" ] , types : [ "main_frame" , "sub_frame" ] } ; export interface RequestWatcherListener { prepareNavigation ( tabId , frameId , hostname ) : void ; commitNavigation ( tabId , frameId , hostname ) : void ; completeNavigation ( tabId , frameId ) : void ; } export class RequestWatcher { private readonly listener : RequestWatcherListener ; public constructor ( listener ) { this . listener = listener ; browser . webNavigation . onBeforeNavigate . addListener ( this . onBeforeNavigate = this . onBeforeNavigate . bind ( this ) ) ; browser . webNavigation . onCommitted . addListener ( this . onCommitted = this . onCommitted . bind ( this ) ) ; browser . webNavigation . onCompleted . addListener ( this . onCompleted = this . onCompleted . bind ( this ) ) ; browser . webRequest . onBeforeRedirect . addListener ( this . onBeforeRedirect = this . onBeforeRedirect . bind ( this ) , WEB_REQUEST_FILTER ) ; } private onBeforeNavigate ( details ) { this . listener . prepareNavigation ( details . tabId , details . frameId , getValidHostname ( details . url ) ) ; } private onCommitted ( details ) { this . listener . commitNavigation ( details . tabId , details . frameId , getValidHostname ( details . url ) ) ; } private onCompleted ( details ) { this . listener . completeNavigation ( details . tabId , details . frameId ) ; } private onBeforeRedirect ( details ) { this . listener . prepareNavigation ( details . tabId , details . frameId , getValidHostname ( details . redirectUrl ) ) ; } }