JavaScript inserted using HTML macro cannot be executed
プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。
このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
症状
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.
診断
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.
原因
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
ソリューション
Refreshing the page will resolve this issue. The JS can actually be executed upon refresh or upon normal viewing.