Making injected script accessible to website

I am wondering if something like https://metamask.io is possible with Safari App Extensions. It basically provides some javascript object to the webpage. The Apple documentation says:

Injected scripts have an implied namespace—you don’t have to worry about your variable or function names conflicting with those of the website author, nor can a website author call functions in your extension. In other words, injected scripts and scripts included in the webpage run in isolated worlds, with no access to each other’s functions or data.


Is there any way around this? Maybe with a whitelist to allow the web page to access certain objects injected into the page?