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:
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 PluginAPI in Site Customizations
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.
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>
_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.
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.
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: