-
-
Save dtmrc/5e23eadb985bd6e2f1db96b20b71afff to your computer and use it in GitHub Desktop.
Inject custom script to main page's document.head, used for bypassing Chrome Extension's Content-Scripts Sandbox.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Drink Responsibly, Blackmagic lives here.'; | |
/** | |
* Inject custom script to main page's document.head. | |
* Used for bypassing Chrome Extension's Content-Scripts Sandbox. | |
*/ | |
/** | |
* @param {{type?: string, src?: string, text?: string}} content | |
* @see Microsoft/vscode#22980, "JSDoc comments are ignored for destructured parameters". | |
* @see Microsoft/typescript#11597, "Intellisense for object properties defined in multi-line JSDOC comments". | |
*/ | |
function __inject__({type, src, text}) { | |
if (src === undefined && text === undefined) return; | |
const _ = document.createElement('script'); | |
_.async = true; | |
if (type !== undefined) _.type = type; | |
if (src !== undefined) _.src = src; | |
if (text !== undefined) _.appendChild(document.createTextNode(text)); | |
if (document.head) { | |
document.head.appendChild(_); | |
} else { // XXX: Used for `run_at: document_start`. | |
document.documentElement.appendChild(_); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HACK: BREAKING ContentScripts Sandbox. | |
__inject__({ | |
type: 'text/javascript', | |
text: `(${ String(__inject__) })({ | |
type: 'module', | |
src: '${ chrome.extension.getURL("wanted_content_script.js") }', | |
})`, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment