I want to load some external scripts in a sandbox page and then on event page uses message passing to communicate with the sandbox page to use those scripts. I am basically following these two documentations:
https://developer.chrome.com/extensions/sandboxingEval https://developer.chrome.com/extensions/manifest/sandbox
This is the manifest.json I use with the sandbox and event page config:
{
"manifest_version": 2,
"name": "Diver",
"description": "Diver",
"version": "0.0.1",
"devtools_page": "devtools.html",
"minimum_chrome_version" : "57",
"background": {
"page": "eventpage.html",
"persistent": false
},
"sandbox": {
"pages": ["sandbox.html"]
}
}
This is the eventpage.html, which loads the sandbox.html in an iframe:
<!doctype html>
<html>
<body>
<iframe id="sandboxFrame" src="sandbox.html"></iframe>
</body>
</html>
This is the sandbox.html, which loads an external script:
<!doctype html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ajv/5.2.3/ajv.min.js"></script>
</head>
<body>
</body>
</html>
When I try it I am getting an error saying the loading of the external script is blocked by content security policy. So looks like this is not allowed according to the doc:
"Starting in version 57, Chrome will no longer allow external web content (including embedded frames and scripts) inside sandboxed pages. Please use a webview instead"
"Also, the CSP you specify may not allow loading external web content inside sandboxed pages."
The doc asks me to use webview but webview is only available in Chrome App. Next I upload sandbox.html into a cdn and replace it in the eventpage.html:
<!doctype html>
<html>
<body>
<iframe id="sandboxFrame" src="https://www.somecdn.com/sandbox.html"></iframe>
</body>
</html>
The external script loads this time, probably because that external page doesn't have the CSP blocking the script.
I don't understand why the same script is blocked when used in sandbox.html in the extension but not when sandbox.html is loaded from an external domain. I know it's because of CSP, but why do Chrome decided to block it this way. I tested it in Chrome 56 and it's not blocked. Only after Chrome 57 it's blocked.