MCPcopy Create free account
hub / github.com/ICBNetwork/web3-Wallet / injectScript

Function injectScript

scripts/inpage-bridge/content-script/index.js:24–39  ·  view source on GitHub ↗

* Injects a script tag into the current document * * @param {string} content - Code to be executed in the current document

(content)

Source from the content-addressed store, hash-verified

22 * @param {string} content - Code to be executed in the current document
23 */
24function injectScript(content) {
25 try {
26 const container = document.head || document.documentElement;
27
28 // synchronously execute script in page context
29 const scriptTag = document.createElement('script');
30 scriptTag.setAttribute('async', false);
31 scriptTag.textContent = content;
32 container.insertBefore(scriptTag, container.children[0]);
33
34 // script executed; remove script element from DOM
35 container.removeChild(scriptTag);
36 } catch (err) {
37 console.error('MetaMask script injection failed', err);
38 }
39}
40
41/**
42 * Determines if the provider should be injected.

Callers 1

index.jsFile · 0.85

Calls 1

errorMethod · 0.45

Tested by

no test coverage detected