I recommend taking a look at this repository: https://github.com/AleCucina/chrome-extension-remote-scripts
It shows a way to work around the restriction using JavaScript AST and an interpreter.