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

Function encodeBody

src/injected/content/requests.js:226–246  ·  view source on GitHub ↗

Doing it here because vault's SafeResponse+blob() doesn't work in injected-web

(body, mode)

Source from the content-addressed store, hash-verified

224
225/** Doing it here because vault's SafeResponse+blob() doesn't work in injected-web */
226async function encodeBody(body, mode) {
227 if (mode === 'fd') {
228 if (!body.length) { // see decodeBody comments about FormData in Chrome
229 return [body, mode];
230 }
231 const fd = new SafeFormData();
232 body::forEach(entry => fd::fdAppend(entry[0], entry[1]));
233 body = fd;
234 }
235 const wasBlob = isInstance(body, BlobProto);
236 const blob = wasBlob ? body : await new SafeResponse(body)::getBlob();
237 const reader = new SafeFileReader();
238 return new SafePromise(resolve => {
239 reader::on(LOAD, () => resolve([
240 reader::getReaderResult(),
241 blob::getBlobType(),
242 wasBlob,
243 ]));
244 reader::readAsDataURL(blob);
245 });
246}

Callers 1

HttpRequestFunction · 0.85

Calls 3

isInstanceFunction · 0.85
onFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected