MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / toggleHeaderInjector

Function toggleHeaderInjector

src/background/utils/requests-core.js:120–140  ·  view source on GitHub ↗
(reqId, headers)

Source from the content-addressed store, hash-verified

118}
119
120export 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

Callers 2

httpRequestFunction · 0.90
clearRequestFunction · 0.90

Calls 1

isEmptyFunction · 0.90

Tested by

no test coverage detected