diff --git a/src/webEngine.ts b/src/webEngine.ts index c14a89e..291242c 100644 --- a/src/webEngine.ts +++ b/src/webEngine.ts @@ -13,6 +13,7 @@ import { export default class WebEngine { private contentProviders: BaseProvider[] = []; private requests: Map = new Map(); + private requestData: Map = new Map(); constructor() { browser.webRequest.onHeadersReceived.addListener( @@ -28,6 +29,7 @@ export default class WebEngine { { urls: [""] }, ["blocking"] ); + browser.webRequest.onCompleted.addListener( this.onCompletedHandler.bind(this), { @@ -108,6 +110,10 @@ export default class WebEngine { if (this.requests.has(details.requestId)) { this.requests.delete(details.requestId); } + + if (this.requestData.has(details.requestId)) { + this.requests.delete(details.requestId); + } } private async onErrorHandler( @@ -116,6 +122,10 @@ export default class WebEngine { if (this.requests.has(details.requestId)) { this.requests.delete(details.requestId); } + + if (this.requestData.has(details.requestId)) { + this.requests.delete(details.requestId); + } } public registerContentProvider(provider: BaseProvider) { @@ -125,4 +135,26 @@ export default class WebEngine { this.contentProviders.push(provider); } + + public getRequestData(requestId: string, key: string) { + if (!this.requestData.has(requestId)) { + return undefined; + } + + const store: any = this.requestData.get(requestId); + + return store[key]; + } + + public setRequestData(requestId: string, key: string, value: any) { + let store: any = {}; + + if (this.requestData.has(requestId)) { + store = this.requestData.get(requestId); + } + + store[key] = value; + + this.requestData.set(requestId, store); + } }