수정: 같은 테마를 사용하지 않는 다른 사이트에서도 이러한 오류가 발생하는 것 같으므로, 이것이 문제의 원인은 아닌 것 같습니다. 그래서 테마 API가 변경된 것이 아닌가 싶습니다. 하지만 이 토픽은 업데이트되지 않았거든요: Using the JS API
결론적으로 새로운 Discourse 업데이트가 CSP(Content Security Policy)를 더 엄격하게 만든 것 같습니다.
이 문제를 어떻게 해결할 수 있을까요? 릴리스 노트에서 CSP나 테마 변경 사항에 대한 내용을 찾지 못했습니다.
실행하려는 제 스크립트는 다음과 같습니다:
<script type="text/discourse-plugin" version="0.0.1">
api.onPageChange(() => {
checkMainPageLoadFeeds();
});
function checkMainPageLoadFeeds() {
// Only load on main page
// Apparently this doesn't work perfectly due to the way discourse works,
// but at least this doesn't cause any issues either...
if(/https?:\/\/[^\/]+\/(categories)?$/.test(window.location.href) ){
// These files are created by a bot running on the same server as this forum
if($("#development-info").text() == ""){
$("#development-info").load("/thrive-feed-bot/devforum-and-github");
$("#announcement-contents").load("/thrive-feed-bot/community-announcements");
}
}
$("#development-heading").off("click").on("click", expandTheFeeds);
$("#announcement-heading").off("click").on("click", expandTheFeeds);
}
function expandTheFeeds(){
let target = $("#development-feed").height() == 200 ? 450 : 200;
$('#development-feed').animate({ height: target + "px" });
$('#development-info').animate({ height: (target - 95) + "px" });
$('#announcement-feed').animate({ height: target + "px" });
$('#announcement-contents').animate({ height: (target - 95) + "px" });
}
$( document ).ready(function(){
checkMainPageLoadFeeds();
})
</script>
그리고 두 번째 스크립트는 다음과 같습니다:
<script type="text/discourse-plugin" version="0.0.1">
api.onAppEvent('modal:body-shown', (data) => {
if(data.title){
if(data.title.match(/.*create.*account.*/)){
$(".create-account.fixed-modal .modal-footer").prepend(getEmailSpamCheckMessage(true));
}
} else {
// Might be forgot password
let element = $(".fixed-modal .forgot-password-modal")
if(element){
element.append(getEmailSpamCheckMessage(false));
}
}
});
function getEmailSpamCheckMessage(register){
return $.parseHTML("<p class='EmailNoteMessage'>If you don't receive an email " +
(register ? "confirmation " : "") + "check your spam folder.<br>" +
"You can also visit our <a href='https://discordapp.com/invite/FZxDQ4H'>discord</a> " +
"if you have trouble " + (register ? "registering" : "receiving emails from us") + ".</p>");
}
</script>
이 스크립트들은 이전에 메타(meta)에 게시한 것으로确信하지만, 이제 그 게시글을 찾을 수 없습니다.
제 문제는 CSP와 관련이 없다고 생각합니다. 기본 테마를 사용하는 사이트(https://forum.revolutionarygamesstudio.com/)에서도 동일한 2개의 오류가 발생하기 때문입니다. 즉, 제 스크립트가 로드되려 시도조차 되지 않는 것으로 보입니다. 커스텀 테마를 사용하는 사이트에서는 페이지 상단 근처의 박스가 자바스크립트를 통해 채워지도록 되어 있는데, 해당 박스들이 비어 있는 상태입니다: https://community.revolutionarygamesstudio.com/
관리자 설정에서 CSP를 끄는 것도 시도해 보았지만, 스크립트 문제는 해결되지 않았고, 대신 2개의 오류가 사라졌습니다(그 결과 retort에서 발생하는 오류 1개만 남게 됨).
수정: 어떤 부분이 변경되어 <script type="text/discourse-plugin" version="0.0.1"> 태그가 더 이상 전혀 로드되지 않게 된 것 같습니다.
수정 2: CSP가 활성화되어 있고 화이트리스트에 아무것도 추가하지 않은 상태에서도, 이 코드는 작동합니다:
<script>
console.log('this loaded just fine');
</script>
하지만 이 코드는 작동하지 않습니다:
<script type="text/discourse-plugin" version="0.0.1">
console.log('this loaded just fine');
</script>
_retort-75a57ba39180becb082af07c57df6a5dd4e16efe0dbd24ec6c4e5d903e138efb.js:188 Uncaught TypeError: Cannot read property 'retort_disabled_categories' of undefined
at _retort-75a57ba39180becb082af07c57df6a5dd4e16efe0dbd24ec6c4e5d903e138efb.js:188
at t.module.exports.u.<computed> (_ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74640)
at t.module.exports.u.<computed> (_ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74470)
at require (_ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74637)
at f (_ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74596)
at _ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74561
at t.module.exports.u.<computed> (_ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74639)
at t.module.exports.u.<computed> (_ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74470)
at require (_ember_jquery-1ed3f3559e6f967733b4088aa729ff7039dff2c09c5a5f787a214b016f58aabc.js:74637)
at t._prepareInitializer (_application-66bcc4126a5a02dd0d99aed67150087a79a427788cc00feaf5e17bf042b73d75.js:6849)
다른 사이트에 대해서는 소스 코드에서 checkMainPageLoadFeeds를 찾을 수 없어 이것이 로드되는지 확실하지 않습니다.