2.5.0.beta5 breaks retort plugin

AI-generated summary

In this support thread titled “2.5.0.beta5 breaks retort plugin,” user Boost reports that after upgrading from Discourse 2.5.0.beta4 to beta5, their custom theme scripts using <script type="text/discourse-plugin"> stopped executing — despite plain <script> tags working — and CSP-related console errors appeared. They suspected theme API changes, but noted the issue also occurred on a site with the default theme. j.jaffeux pointed to a CSP mitigation guide, but Boost clarified CSP wasn’t the root cause, as disabling it didn’t restore script execution. Instead, j.jaffeux identified a JavaScript error in the third-party “retort” plugin on Boost’s site, which appeared to halt execution of other plugins, including theme scripts. Boost confirmed the suspicion: removing retort restored script functionality. j.jaffeux verified that text/discourse-plugin scripts still work on Meta, suggesting the issue was specific to retort’s error. After rebuilding without retort, Boost confirmed the fix and marked it as the solution, noting they’d reported the issue upstream on the retort plugin thread. mcdanlj later confirmed the fix worked for them too after retort was updated.

I just updated from 2.5.0.beta4 to 2.5.0.beta5 and now my two scripts that I have in my theme no longer seem to run, and I see this in my browser console:

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

Edit: it seems I get these on my other site as well that I don’t have the same theme on, so this isn’t the problem. So I guess the theme API changed? Even though this topic has not been updated: Using the JS API

Basically it seems that the new discourse update made the CSP more strict.
How would I go about fixing this? I didn’t find anything regarding CSP or theme changes in the release notes.

This is my script I want to run:

<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>

And this is the second one:

<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>

Which I’m sure I have posted here on meta before but can’t find that post now.

All you want to know about CSP is here:

I don’t think my problem is with CSP, as I get the same 2 errors on a site (https://forum.revolutionarygamesstudio.com/) which uses the default theme. So it seems that my scripts aren’t even attempted to be loaded. On the site with a custom theme the boxes near the top of the page stay blank as javascript is used to fill them: https://community.revolutionarygamesstudio.com/
I also tried toggling CSP off in the admin section, but that didn’t seem to fix my scripts, but did make the 2 errors go away (leaving only one coming from retort).

Edit: So I’m thinking that something changed which makes it so that <script type="text/discourse-plugin" version="0.0.1"> don’t load at all anymore

Edit 2: So even with CSP enabled and nothing added to whitelist, this works:

<script>
console.log('this loaded just fine');
</script> 

But this doesn’t:

<script type="text/discourse-plugin" version="0.0.1">
console.log('this loaded just fine');
</script> 

You have a js error with retort on https://community.revolutionarygamesstudio.com/

_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)

Concerning the other site, I can’t find checkMainPageLoadFeeds in the source code so not sure this is loaded.

Can find it on https://community.revolutionarygamesstudio.com/ though:

So try to fix your js error with this plugin.

That’s what I’m seeing. See my update in the previous post, it seems that the script type "text/discourse-plugin" doesn’t run, but a plain script tag does.

I noticed that, I have the latest retort version:
Kuvakaappaus - 2020-05-31 13-07-36

So that plugin having an error is stopping the plugin defined in the theme from running?

I just tested here on meta and this is correctly called:

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

This is not an official plugin, don’t know much about it sorry.

It’s possible yes, try to deactivate or even remove it and see if it fixes your issue.

Rebuilding without retort in my list of plugins, “fixes” the issue. Thanks for the help. I didn’t consider that one plugin failing could make any other plugin to fail as well. I’ll try to remember this in the future to check before reporting an issue.

I’ll mark this as the solution, while waiting for a new version of retort so that I can enable it again.

Looks like issues with the latest discourse have already been reported:

I confirm the fix to retort has resolved this issue for me.