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

Function HttpRequest

src/injected/content/requests.js:60–83  ·  view source on GitHub ↗

* @param {GMReq.Message.Web} msg * @param {VMScriptInjectInto} realm * @returns {Promise }

(msg, realm)

Source from the content-addressed store, hash-verified

58 * @returns {Promise<void>}
59 */
60 async HttpRequest(msg, realm) {
61 if (IS_FIREFOX) msg = nullObjFrom(msg); // copying into our realm to set its props freely
62 else setPrototypeOf(msg, null);
63 const { url } = msg;
64 const data = !IS_FIREFOX && msg.data;
65 const uaData = getUAData && navigator::getUAData();
66 const sch = url::slice(0, 5);
67 const isDataUri = sch === 'data:';
68 if (isDataUri || sch === 'blob:') {
69 return requestVirtualUrl(msg, url, isDataUri, realm);
70 }
71 requests[msg.id] = {
72 __proto__: null,
73 realm,
74 [kXhrType]: msg[kXhrType],
75 };
76 // In Firefox we recreate FormData in bg::decodeBody
77 if (data && data.length > 1 && data[1] !== 'usp') {
78 // TODO: support huge data by splitting it to multiple messages
79 msg.data = await encodeBody(data[0], data[1]);
80 }
81 msg.ua = getUAProps::map((fn, i) => (!i ? navigator : uaData)::fn());
82 return sendCmd('HttpRequest', msg);
83 },
84 AbortRequest: true,
85 ParseHTML(args, realm, nodeRet) {
86 nodeRet[0] = safeApply(parseFromString, new SafeDOMParser(), args);

Callers

nothing calls this directly

Calls 5

sendCmdFunction · 0.90
nullObjFromFunction · 0.85
getUADataFunction · 0.85
requestVirtualUrlFunction · 0.85
encodeBodyFunction · 0.85

Tested by

no test coverage detected