Skip to content

Commit

Permalink
one portListener
Browse files Browse the repository at this point in the history
  • Loading branch information
hfmanson committed Jun 22, 2020
1 parent 517eba7 commit a65eeeb
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let lastResponseGlobal = { };
let mech;
let c2c = { };
let resolveGlobal = { };

const
target = "<all_urls>"
Expand Down Expand Up @@ -59,22 +60,15 @@ const
}
mech = undefined;
delete c2c[requestDetails.requestId];
delete resolveGlobal[requestDetails.requestId];
}, portListener = (response) => {
console.log("response " + response.requestId + ": " + JSON.stringify(response));
lastResponseGlobal[response.requestId] = response;
resolveGlobal[response.requestId](response.extraInfoSpec);
}, asyncRedirect = (attrs) => {
return new Promise((resolve, reject) => {
const
portListener = (response) => {
if (response.requestId === attrs.requestId) {
port.onMessage.removeListener(portListener);
console.log("response " + response.requestId + ": " + JSON.stringify(response));
console.log("attrs.requestId: " + attrs.requestId);
lastResponseGlobal[response.requestId] = response;
resolve(response.extraInfoSpec);
}
}
;

console.log("posting " + attrs.requestId + ": " + JSON.stringify(attrs));
port.onMessage.addListener(portListener);
resolveGlobal[attrs.requestId] = resolve;
port.postMessage(attrs);
});
}, binaryToHex = (binary) => {
Expand Down Expand Up @@ -199,6 +193,8 @@ const
}
;

port.onMessage.addListener(portListener);

browser.webRequest.onHeadersReceived.addListener(
onHeadersReceived,
{ urls: [ target ] },
Expand Down

0 comments on commit a65eeeb

Please sign in to comment.