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

Function triageRealms

src/background/utils/preinject.js:605–633  ·  view source on GitHub ↗
(scripts, forceContent, tabId, frameId, bag)

Source from the content-addressed store, hash-verified

603}
604
605function triageRealms(scripts, forceContent, tabId, frameId, bag) {
606 let code;
607 let wantsPage;
608 const toContent = [];
609 for (const /**@type{VMInjection.Script}*/ scr of scripts) {
610 const metaStr = scr[META_STR];
611 if (isContentRealm(scr[INJECT_INTO], forceContent)) {
612 if (!metaStr[0]) {
613 const [, i, from, to] = metaStr;
614 metaStr[0] = scr[__CODE][i].slice(from, to);
615 }
616 code = '';
617 toContent.push([scr.id, scr.key.data]);
618 } else {
619 metaStr[0] = '';
620 code = forceContent ? ID_BAD_REALM : scr[__CODE];
621 if (!forceContent) wantsPage = true;
622 }
623 scr.code = code;
624 }
625 if (bag) {
626 bag[INJECT][PAGE] = wantsPage || triagePageRealm(bag[MORE]);
627 }
628 if (toContent[0]) {
629 // Processing known feedback without waiting for InjectionFeedback message.
630 // Running in a separate task as executeScript may take a long time to serialize code.
631 setTimeout(injectContentRealm, 0, toContent, tabId, frameId);
632 }
633}
634
635function triagePageRealm(env, forceContent) {
636 return env?.[SCRIPTS].some(isPageRealmScript, forceContent || null);

Callers 3

GetInjectedFunction · 0.85
InjectionFeedbackFunction · 0.85
prepareXhrBlobFunction · 0.85

Calls 2

isContentRealmFunction · 0.85
triagePageRealmFunction · 0.85

Tested by

no test coverage detected