CSP Safari bug repro
There appears to be a discrepancy between how Safari handles CSP policies for extension pages compared to how other browsers do so.
This causes problems for adapting to Google Docs' new canvas mode which requires injecting script in this manner.
Steps to reproduce
In Safari:
- Load
CSP bug repro/CSP bug repro.xcodeprojin XCode 13. - Run the project
- It should provide a Window with a button to jump to Safari and enable the extension
- You will need to enable unsigned extensions using Develop → Allow Unsigned Extensions
- Navigate to docs.google.com
- Load any Google doc
- Press the star button on the toolbar, granting permission to run if needed.
- Open the Javascript console from the Develop menu
- Look for the line beginning,
"Script ran...". - As per the message look for CSP errors prior to that line.
- Enter
window.testme+ Enter an observe the result.
Expected results:
- No CSP errors
"ok"is returned
Actual results:
- Several CSP errors of the form "Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy".
undefinedis returned.
To compare with Firefox / Chrome:
- Install
npxglobally. - From the root
csp-bugfolder, runnpx web-ext runfor Firefox, ornpx web-ext run -t chromiumfor Chrome. - Similarly, load any document from docs.google.com and check the Developer console (F12 → Console).