Last active
August 28, 2019 04:43
-
-
Save daltonmenezes/c6f5e15f012bf58a7387acbab2cf7a14 to your computer and use it in GitHub Desktop.
Convert your external module to String and catches the module body to inject using executeJavaScript on Electron
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
const prepareModuleForInjection = code => { | |
const moduleBody = /(?<=\{return\s).*(?=})|(?<=({(?![return]))).*(?=})|(?<=\=>\s)(?=[a-z]).*|(?<=\=>)\n.*/gsi | |
const [extractedBody] = String(code).match(moduleBody) || '' | |
return extractedBody | |
? `${extractedBody.trim()}\n\n` | |
: '' | |
} | |
webview.executeJavaScript( | |
prepareModuleForInjection(yourModule) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment