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

Function startHandshake

src/injected/content/inject.js:109–119  ·  view source on GitHub ↗

A page can read our script's textContent in a same-origin iframe via DOMNodeRemoved event. * Directly preventing it would require redefining ~20 DOM methods in the parent. * Instead, we'll send the ids via a temporary handshakeId event, to which the web-bridge * will listen only during its

()

Source from the content-addressed store, hash-verified

107 * will listen only during its initial phase using vault-protected DOM methods.
108 * TODO: simplify this when strict_min_version >= 63 (attachShadow in FF) */
109 function startHandshake() {
110 /* With `once` the listener is removed before DOMNodeInserted is dispatched by appendChild,
111 * otherwise a same-origin parent page could use it to spoof the handshake. */
112 window::on(handshakeId, handshaker, { capture: true, once: true });
113 inject({
114 code: `(${VMInitInjection}(${IS_FIREFOX},'${handshakeId}','${vaultId}'))()`
115 + `\n//# sourceURL=${VM_UUID}sandbox/injected-web.js`,
116 });
117 // Clean up in case CSP prevented the script from running
118 window::off(handshakeId, handshaker, true);
119 }
120 function handshaker(evt) {
121 pageInjectable = true;
122 evt::stopImmediatePropagation();

Callers 1

injectPageSandboxFunction · 0.85

Calls 3

onFunction · 0.85
injectFunction · 0.85
offFunction · 0.85

Tested by

no test coverage detected