Page MenuHomePhabricator

"TypeError: context.$textarea.textSelection is not a function" in WikiEditor extension
Closed, ResolvedPublic

Description

Context:
We are currently seeing 200+ client error messages in Logstash pertaining to a JavaScript error that might be causing functionality disruption during the editing process.

Error Details:
Error Message: "TypeError: context.$textarea.textSelection is not a function"
Error Class: TypeError
Occurrence: During editing action within the "Project" namespace on the "enwiki" Wikipedia project

Impact:
The error occurs while trying to call the non-existent function textSelection on the object context.$textarea.

Sample tack Trace:
Originated in "jquery.wikiEditor.js" at line 19, column 82
Influenced by "ext.wikiEditor.js" at line 4, column 695
Reference to jQuery library ("jquery-3.5.1.min.js") at line 2, column 30005
Related to Deferred object at line 2, column 30307

Event Timeline

Aklapper renamed this task from Fix Needed for JavaScript TypeError in WikiEditor Plugin to "TypeError: context.$textarea.textSelection is not a function" in WikiEditor extension.Aug 10 2023, 8:39 AM
Aklapper added a project: JavaScript.
thcipriani moved this task from Untriaged to Aug 2023 on the Wikimedia-production-error board.
thcipriani subscribed.

note: on Aug 9th 1.41.0-wmf.20 was the active wiki version.

Would imply that the jquery.textSelection module isn't loaded, I guess? (Which it should be -- it's a dependency of the package that contains ext.wikiEditor.js) Or perhaps that somehow context.$textarea isn't actually a jQuery object -- it's created via $(this) in the initializer, but it's also stored in data wikiEditor-context where something could modify it.

Anyway, can't reproduce it on https://en.wikipedia.org/w/index.php?title=Wikipedia:Sandbox&action=edit. If you have the logstash link to the error that would be helpful for digging in to it.

I too struggle to see the codepath that causes this to happen. I can't see any gadgets modifying wikiEditor-context, and the $textarea property should always be set. There have been some changes to jquery.textSelection, so maybe in some circumstances it is silently failing to load completely?

I looked at a more-complete stack trace (on this specific error):

at jquery.wikiEditor.js/$.fn.wikiEditor https://en.wikipedia.org/w/load.php?lang=en&modules=ext.wikiEditor&skin=vector&version=13m6h:19:82
at ext.wikiEditor.js/mw.addWikiEditor https://en.wikipedia.org/w/load.php?lang=en&modules=ext.wikiEditor&skin=vector&version=13m6h:4:695
at ext.wikiEditor.js/< https://en.wikipedia.org/w/load.php?lang=en&modules=ext.wikiEditor&skin=vector&version=13m6h:4:574
at e https://code.jquery.com/jquery-3.5.1.min.js:2:30005
at Deferred/then/l/</t< https://code.jquery.com/jquery-3.5.1.min.js:2:30307

...so, I think this likely is a gadget or userscript doing something unwise. There's no reason for that external jQuery to be loaded unless someone is doing something strange, and if you're already loading external-jquery then you might well be hard-embedding other things without fetching their dependencies...

Global search suggests that there's only one place that that particular version of external jquery is being called, added in November 2022.

There are a bunch of other people loading different versions of jQuery.

I've checked the remaining matches in global search. Most are actually commented references. There are full html pages but these won't trigger such problems. Remaining are either properly guarded on the jQuery variable or the user isn't active any longer.

The only one that gives me some concern is https://fi.wikipedia.org/wiki/Käyttäjä:Kulmalukko/monobook.js But possibly the user switched skins and this is not in use either ? Still we might want to inform that user specifically

Jdlrobson claimed this task.
Jdlrobson subscribed.

Looks like this was a gadget error. Not seeing these in logs anymore except one relating to a gadget which I just patched.