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

Function HttpRequested

src/injected/content/requests.js:107–141  ·  view source on GitHub ↗

* @param {GMReq.Message.BG} msg * @returns {Promise }

(msg)

Source from the content-addressed store, hash-verified

105 * @returns {Promise<void>}
106 */
107 async HttpRequested(msg) {
108 const { id, data } = msg;
109 const req = requests[id];
110 if (!req) {
111 if (process.env.DEV) console.warn('[HttpRequested][content]: no request for id', id);
112 return;
113 }
114 if (hasOwnProperty(msg, 'chunk')) {
115 processChunk(req, data, msg);
116 return;
117 }
118 let response = data?.[kResponse];
119 if (response != null) {
120 if (msg.blobbed) {
121 response = await importBlob(response, isBlobXhr(req));
122 sendCmd('RevokeBlob', response);
123 } else if (msg.chunked) {
124 processChunk(req, response);
125 response = req[CHUNKS];
126 delete req[CHUNKS];
127 if (isBlobXhr(req)) {
128 response = makeSafeBlob(response, msg.contentType);
129 } else if (req[kXhrType]) {
130 response = response::getTypedArrayBuffer();
131 } else {
132 // sending text chunks as-is to avoid memory overflow due to concatenation
133 }
134 }
135 data[kResponse] = response;
136 }
137 if (msg.type === LOADEND && !msg[UPLOAD]) {
138 delete requests[msg.id];
139 }
140 sendHttpRequested(msg, req.realm);
141 },
142});
143
144/**

Callers

nothing calls this directly

Calls 6

sendCmdFunction · 0.90
makeSafeBlobFunction · 0.90
processChunkFunction · 0.85
importBlobFunction · 0.85
isBlobXhrFunction · 0.85
sendHttpRequestedFunction · 0.85

Tested by

no test coverage detected