Strange TinyMCE Javascript error

Strange TinyMCE Javascript error

by Howard Miller -
Number of replies: 14
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

We have a problem on a site where the TinyMCE editor simply fails to appear.  It looks like this...


When looking at the Javascript console for this page one sees...

SyntaxError: expected expression, got '<' editor_plugin.js:1:0

SyntaxError: expected expression, got '<' editor_plugin.js:1:0

SyntaxError: expected expression, got '<' editor_plugin.js:1:0

SyntaxError: expected expression, got '<' editor_plugin.js:1:0

The stylesheet http://www.blahblahblah.org.uk/ was not loaded because its MIME type, "text/html", is not "text/css".


Following those syntax errors, the lead to the plugins files for TinyMCE. Disabling the plugins reduces the number of errors but you can't disable them all and that's not really the point anyway. 

The same code/theme/everything works fine on a different server. The same code base as a clean install works fine on the same server. So, it seems to be a function of that code with that data on that server. Changing one thing fixes it. 

Anybody got any ideas because we haven't? smile


Average of ratings: -
In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Mauno Korpelainen -

Not exactly a similar case but one of our old upgraded (1.9.x > 2.x) sites had problems with a couple of plugins. It turned out to be a config.php problem:

1.9.x config.php started with lines

unset($CFG);
$CFG = new stdClass();

and after upgrading 2.x site config.php should have started with

unset($CFG);
global $CFG;
$CFG = new stdClass();

(but it did not because config.php was write protected during upgrading)

There were of course some other different lines like ($CFG->dirroot), $CFG->dbtype, $CFG->dblibrary and $CFG->dboptions but I suppose that our plugin problem was caused by missing global $CFG; line

On the other hand config.php used to cause similar problems already years ago (before last ?> was removed) but config.php might as well have some extra lines at the beginning...  https://tracker.moodle.org/browse/MDL-10379



In reply to Mauno Korpelainen

Re: Strange TinyMCE Javascript error

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Thanks... but thought about that smile

The site was moved and upgraded all over the place so I took a fresh copy of config-dist.php and re-did all the settings. No difference sad

In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Mauno Korpelainen -

How about Site administration > Plugins > Text editors > TinyMCE HTML editor >  General settings ?

(For example some extra character in settings of Editor toolbar)

In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Mauno Korpelainen -

I might try next Site administration > Appearance > Themes > Theme settings > Theme designer mode ON to compare source without cache and with cache if there is some strange code that might break javascripts or css minimization process - and check Additional HTML ... wink

In reply to Mauno Korpelainen

Re: Strange TinyMCE Javascript error

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I was pretty sure we've tried all of the above but I've just tried it all again. Turned off all the caching I can find; even turned off opcache in php.ini and no difference whatsoever. 

The TinyMCE editor settings have not been changed - all at their default settings. 

We do have a custom theme but it's not that. Selecting a core theme is just the same smile

In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Have you grepped the code to verify there are no merge conflict markers. (Just on the basis that the error says unexpected <)

In reply to Tim Hunt

Re: Strange TinyMCE Javascript error

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I have now smile   Nope, not that smile

In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Another thought: is there a PHP error message appearing in the CSS / JavaScript sent to the browser?

In reply to Tim Hunt

Re: Strange TinyMCE Javascript error

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well if there is I can't find it. There's nothing in the apache error log. 

I can't see anything in the console but I might be doing it wrong. I'm a bit outside of my comfort zone with javascript TBH.

In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

My guess would be that mimetype on the js is somehow html instead of text so the server or browser is inserting <html> at the start. Apache may have a directive that is treating *.js as php files. Is all the other javascript working?

In reply to Daniel Thies

Re: Strange TinyMCE Javascript error

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes - just this. Other sites on the same server with the same code (straight pull) from our git repo all work fine. 

In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Mauno Korpelainen -

Next guess: "something" might break the path that plugin tried to use in finding editor_plugin.js (or the file is not there)

Instead of js file the site gives 404 page (file not found) - you just need to find why (some custom code in a block, custom jQuery, permissions, ... )

https://github.com/carhartl/jquery-cookie/issues/347

Try inspecting with different browsers: FF, Chrome and IE (F12)


In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Right... I think I know what is happening. But I don't know why...

The editor is trying to load plugins. Here is an example...

http://www.blahblahblah.org.uk/lib/editor/tinymce/plugins/loader.php/moodleemoticon/-1/editor_plugin.js

Which you would think should probably return some javascript. It isn't... it's returning the (HTML) front page of the site. Hence the error... it's choking on the unexpected <!DOCTYPE> at the start.

I'm pretty sure that this is nothing to do with loader.php per se, because...

- if I remove everything after loader.php it failed with an expected 'file not found' error
- if I put breakpoints in loader.php (right at the start) it loads the home page regardless

So... I think there's something in my web server setup that's making that particular URL (and one's just like it) redirect to the home page. Maybe....

In reply to Howard Miller

Re: Strange TinyMCE Javascript error

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Found it...

It was caused by a bunch of Rewrite rules in the apache config. I don't know the back-story but my colleague had added them on the recommendation of some posting in the Moodle Partner forums for fixing some reported vulnerability. It obviously breaks TinyMCE but we might well be the first to try this combination. 

Oh well.... thanks for all your suggestions. In a round-about way you all helped a lot smile