2.5.0.beta5 导致 retort 插件失效

我刚刚从 2.5.0.beta4 更新到了 2.5.0.beta5,现在我的主题中原本运行的两个脚本似乎无法执行了。我在浏览器控制台中看到了以下信息:

Content Security Policy: Sivuston asetukset estivät resurssin lataamisen osoitteesta inline ("script-src"). injectGlobalHook.js:1:1760
Content Security Policy: Sivuston asetukset estivät resurssin lataamisen osoitteesta inline ("script-src"). pagewrap.bundle.js:1:1151

编辑:看起来我在另一个没有使用相同主题的网站上也遇到了同样的问题,所以这应该不是主题的问题。那么是不是主题 API 发生了变化?尽管这个主题帖并没有更新:Using the JS API

基本上,似乎是新的 Discourse 更新使得 CSP(内容安全策略)变得更加严格了。
我该如何解决这个问题?我在发布说明中没有找到任何关于 CSP 或主题变更的说明。

这是我想要运行的脚本:

<script type="text/discourse-plugin" version="0.0.1">
api.onPageChange(() => {
	checkMainPageLoadFeeds();
});

function checkMainPageLoadFeeds() {
    // 仅在主页加载
    // 由于 Discourse 的工作方式,这似乎并不能完美生效,
    // 但至少不会引起任何问题...
    if(/https?:\/\/[^\/]+\/(categories)?$/.test(window.location.href) ){
        // 这些文件是由运行在与本论坛相同服务器上的机器人创建的
        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 {
        
        // 可能是忘记密码的情况
        let element = $(".fixed-modal .forgot-password-modal")
        if(element){
            element.append(getEmailSpamCheckMessage(false));
        }
    }
	
});

function getEmailSpamCheckMessage(register){
    return $.parseHTML("<p class='EmailNoteMessage'>如果你没有收到邮件 " + 
                (register ? "确认" : "") + "请检查你的垃圾邮件文件夹。<br>" +
                "如果遇到问题,你也可以访问我们的 <a href='https://discordapp.com/invite/FZxDQ4H'>Discord</a> " +
                (register ? "注册" : "接收我们的邮件") + "。</p>");
}
</script>

我确定我之前在这里的 Meta 上发布过这些内容,但现在找不到那个帖子了。

所有关于 CSP 的信息都在这里:

我不认为我的问题出在 CSP 上,因为在另一个使用默认主题的网站(https://forum.revolutionarygamesstudio.com/)上,我也遇到了相同的两个错误。看来我的脚本甚至没有被尝试加载。在使用自定义主题的网站(https://community.revolutionarygamesstudio.com/)上,页面顶部的几个框保持空白,因为它们是通过 JavaScript 填充的。

我还尝试在管理后台关闭 CSP,但这似乎并没有解决我的脚本问题,只是让那两个错误消失了(只剩下一个来自 retort 的错误)。

编辑:所以我怀疑是某些变更导致 <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> 

您在 https://community.revolutionarygamesstudio.com/ 上遇到了与 Retort 相关的 JavaScript 错误:

_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,因此不确定它是否已加载。

不过,在 https://community.revolutionarygamesstudio.com/ 上可以找到它:

请尝试使用此插件修复您的 JavaScript 错误。

我也看到了同样的情况。请看我在上一帖中的更新,似乎类型为 "text/discourse-plugin" 的脚本没有运行,但普通的 script 标签可以运行。

我注意到了这一点,我使用的是最新版本的 retort:
Kuvakaappaus - 2020-05-31 13-07-36

所以是这个插件的错误导致主题中定义的插件无法运行吗?

我刚刚在 meta 上测试了一下,以下代码可以正常调用:

<script type="text/discourse-plugin" version="0.1">
</script>

这不是官方插件,我不太了解,抱歉。

有可能。你可以尝试停用甚至卸载它,看看是否能解决你的问题。

在我的插件列表中移除 Retort 后,问题“解决”了。感谢帮助。我之前没考虑到一个插件失败会导致其他插件也失败。以后在报告问题前,我会先检查这一点。

我将标记此回复为解决方案,同时等待 Retort 的新版本发布,以便重新启用它。

看来关于最新 Discourse 的问题已有相关报告:

我确认对 retort 的修复已解决了我的问题。