JavaScript inserted using HTML macro cannot be executed
Symptoms
Some JavaScript (specifically those with functions) inserted using the HTML macro cannot be executed upon saving a Confluence page. When previewing the page (using the Editor), the JS can successfully be executed.
Diagnosis
This issue only occurs in Chrome. After saving the page, going to Developer Tool > Console will produce the following error:
Refused to execute a JavaScript script. Source code of script found within request.
Cause
The error is thrown when the page is saved via a POST and then retrieved via a GET. This is actually a security measure put in place by the Chrome browser in order to prevent XSS (cross-site scripting) attacks.
For more information regarding this, please refer to the following links:
- Security in Depth: New Security Features
- Refused to execute a JavaScript script. Source code of script found within request
Resolution
Refreshing the page will resolve this issue. The JS can actually be executed upon refresh or upon normal viewing.