(reqId, headers)
| 118 | } |
| 119 | |
| 120 | export function toggleHeaderInjector(reqId, headers) { |
| 121 | if (headers) { |
| 122 | /* Listening even if `headers` array is empty to get the request's id. |
| 123 | * Registering just once to avoid a bug in Chrome: |
| 124 | * it adds a new internal registration even if the function reference is the same */ |
| 125 | if (isEmpty(headersToInject)) { |
| 126 | API_EVENTS::forEachEntry(([name, [listener, ...options]]) => { |
| 127 | browser.webRequest[name].addListener(listener, API_FILTER, options); |
| 128 | }); |
| 129 | } |
| 130 | // Adding even if empty so that the toggle-off `if` runs just once even when called many times |
| 131 | headersToInject[reqId] = headers; |
| 132 | } else if (reqId in headersToInject) { |
| 133 | delete headersToInject[reqId]; |
| 134 | if (isEmpty(headersToInject)) { |
| 135 | API_EVENTS::forEachEntry(([name, [listener]]) => { |
| 136 | browser.webRequest[name].removeListener(listener); |
| 137 | }); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Imitating https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/getAllResponseHeaders |
no test coverage detected