Jump to content

User:Jdlrobson/User scripts with client errors

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by Jdlrobson (talk | contribs) at 02:17, 12 January 2021 (→‎Top errors). It may differ significantly from the current version.

You can help fix many of the JavaScript errors on Wikipedia's many projects! This wiki page accompanies my article Diving into Wikipedia's ocean of errors.

You can help me by fixing the associated gadgets, or sharing this page with maintainers who might be able to fix the errors.

Many editors use scripts and gadgets which throw JavaScript errors. Now that we track these errors, we should address these issues to make these tools more reliable and to protect the privacy of these users.

For those with access to Logstash please view the the logstash dashboard to identify bugs and using the stack trace and file_uri locate and fix the most regularly occuring editors.

If you do not have access to Logstash, but are able to edit user scripts you can also help! I hope to regularly update this page with links to scripts with problems. I will list the script causing the error, the error being thrown and the frequency at which it occurs. Please feel free to edit this page to mark any bugs you have fixed.

My hope is to regularly update this page with anonymized data.

Why fix?

  • Help make non gadget errors easier to uncover and help us build better software
  • More stable scripts and gadget for you
  • Fewer pings from this page.
  • Protect your privacy. If you are throwing an error, and you are the only person using a gadget or script, you are leaking information about your viewing habits to those trusted with this data.
  • Fixing errors helps us identify and allow other users to fix errors in their own scripts!

What if my code is unmaintained?

If you are not maintaining the code, it is in the best interest of everyone, that you blank the page and/or get the page deleted. If users want to continue to use and maintain your script they can restore it themselves in their own user namespace and it will be easier to drive changes, particularly if the script is a user script.

How to fix?

Uncaught SyntaxError

Someone/something/possibly you is possibly loading a script as CSS instead of JS. If it's not you, you may be able to find out who using https://global-search.toolforge.org/? or asking users using the script using your local community portal. Usually this means the user is using importScript instead of importStylesheet or passing ctype=text/javascript to mw.loader.using rather than ctype=text/css

ReferenceErrors

You are using a variable that may or may not exist. The script likely doesn't work. This may be helped by prefixing `window.` to signal you are accessing a global variable or taking a defensive programming approach to check its type. Clearing the wiki page may be a solution.

In the case of wg prefixed variables please use mw.config e.g. mw.config.get('wgPageName') rather than wgPageName.

Alternatively, review ResourceLoader/Migration_guide_(users) for migration guidelines.

As a last resort, use typeof to check if the variable exists e.g.

// Code that will work 
if (typeof mwCustomEditButtons !== 'undefined') {
 // run code
 window.mwCustomEditButtons.push('btn')
}}

// Note the following will not work:
if (mwCustomEditButtons) {
 // run code
}}

TypeError

If you have an error such as TypeError: document.querySelector(...) is null it means you are trying to query something that doesn't exist - for example the first item in an empty array. This can happen when you use querySelector as that may return null.

// bad
var x = document.querySelector('.element').getElementsByTagName('li');

// good
var el = document.querySelector('.element');
if (el) {
    var x = el.getElementsByTagName('li');
}

Error: AJAX error: error / custom errors

You likely have a script that itself throws errors. eg.

throw new Error("my script error")

If you want to deal with this error please get a logstash account to further debug this. If the purpose of the code is to alert yourself to errors, please use mw.log.warn or mw.log.error - this will ensure a warning appears in your JavaScript console but does not add noise to those using logstash.

Script errors

These errors occur when your script is being loaded by another project. e.g. A script on commons is being loaded on French Wikipedia. At the current time we are unable to know the error that's been thrown or the stack trace (see https://raygun.com/blog/script-error/ for more information), but if there are more than 2 errors for your script, it is likely script error is being caused by the identifiable error. If it is the only error, it's possible you might be able to uncover the stack trace and error using your developer console and manual testing by loading on those wikis.

In the case of a global user script on meta.wikimedia, although your script runs on meta.wikimedia.org it is incompatible with one of the wikis you frequent. If you don't understand the code you are running please consider blanking the page with the code.

Top errors

Last updated 11th January

file_url.raw: Descending normalized_message.raw: Descending # Possible contact Repeat entry Types of error
url Uncaught TypeError: Cannot read property expandtemplates of null/ Uncaught TypeError: Cannot read property query of null 86 @User:Holek true 2
url Uncaught TypeError: Cannot read property toLowerCase of undefined/ Uncaught TypeError: Cannot read property 1 of null/ TypeError: country is undefined 86 @User:js false 3
url ReferenceError: wgAction is not defined 56 @User:Behaafarid false 1
url TypeError: this is undefined 51 @User:Holmium true 1
url Uncaught ReferenceError: editToolExtentionGroups is not defined 46 @User:Mizusumashi false 1
url Uncaught ReferenceError: editToolExtentionGroups is not defined 44 @User:Mizusumashi false 1
url TypeError: null is not an object (evaluating wikEd.paste.range = range.cloneRange())/ TypeError: wikEd.paste is null/ Uncaught TypeError: Cannot set property range of null/ TypeError: node is null/ Uncaught TypeError: Cannot read property replace of undefined 37 @User:Od1n true 5
url ReferenceError: Ajax is not defined 34 @User:Codeispoetry false 1
url Uncaught TypeError: Cannot read property replace of undefined/ TypeError: editbutton is undefined 29 @User:Andriy.v true 2
url Uncaught TypeError: Cannot read property cloneNode of undefined/ TypeError: e is undefined 28 @User:Vlsergey true 2
url Uncaught Error: parsererror 28 @User:Chiefwei false 1
url Error: parsererror/ Uncaught TypeError: Cannot read property addEventListener of null 27 @User:Chiefwei true 2
url Uncaught TypeError: Cannot set property innerHTML of null 24 @User:Radmir_Far false 1
url TypeError: toolsPortlet is undefined/ Uncaught TypeError: Cannot read property appendChild of undefined 22 @User:DrSauron false 2
url Uncaught TypeError: Cannot read property getElementById of null/ TypeError: mediaWiki.util.jsMessage is not a function/ TypeError: placetoaddvm is undefined 15 @User:DerHexer false 3
url Uncaught TypeError: Cannot read property childNodes of null 13 @User:Bluedeck false 1
url Uncaught TypeError: Cannot set property value of null/ TypeError: document.getElementById(...) is null/ TypeError: null is not an object (evaluating document.getElementById(wpUploadDescription).value = General) 12 @User:علاء true 3
url TypeError: $(...).suggestions is not a function 12 @User:Der_Buckesfelder false 1
url Uncaught TypeError: Cannot read property 1 of null/ TypeError: ahref.match(...) is null 11 @User:Kaligula false 2
url Uncaught ReferenceError: appendCSS is not defined 11 false 1

Discussions

11th Jan 2021

Please add ambassador for https://yo.wikipedia.org/w/index.php?title=MediaWiki:Edittools.js Dear @User:Holek, @User:js, @User:Behaafarid, @User:Holmium, @User:Mizusumashi, @User:Mizusumashi, @User:Od1n, @User:Codeispoetry, @User:Andriy.v, @User:Vlsergey, @User:Chiefwei, @User:Chiefwei, @User:Radmir_Far, @User:DrSauron, @User:DerHexer, @User:Bluedeck, @User:علاء, @User:Der_Buckesfelder, @User:Kaligula, , @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 02:15, 12 January 2021 (UTC)

4th January

Dear @User:Zanaq, @User:Neechalkaran, @User:Abbas_dhothar, @User:Axxgreazz, @User:Tacsipacsi, @User:Holmium, @User:SM7, @User:Axxgreazz, @User:Ggenellina, @User:Kaleem_Bhatti, @User:Axxgreazz, @User:Andriy.v, @User:Chiefwei, @User:Vlsergey, @User:Axxgreazz, @User:Michał_Sobkowski, @User:علاء, @User:Zanaq, @User:Od1n, @User:Holek, @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 21:40, 4 January 2021 (UTC)

17th December

Dear @User:Axxgreazz, @User:Chiefwei, @User:Schnark, @User:1Veertje, @User:Wikitanvir, @User:MichaelSchoenitzer, @User:Od1n, @User:Mizusumashi, @User:Xiplus, @User:Neechalkaran, @User:Chiefwei, @User:DerHexer, @User:Mizusumashi, @User:JohanahoJ, , @User:Teester, @User:Alexander_Misel, @User:E_THP, @User:PiRSquared17, @User:علاء, @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 21:03, 17 December 2020 (UTC)


12th December

Dear @User:Od1n, @User:РDD3, @User:Schnark, @User:1Veertje, @User:Matěj_Suchánek, @User:Mizusumashi, @User:DrSauron, @User:Mizusumashi, @User:Zanaq, @User:Lucas_Werkmeister, @User:Zanaq, @User:Chiefwei, @User:Tacsipacsi, @User:Malarz_pl, @User:Ggenellina, @User:Axxgreazz, @User:Xiplus, @User:Wikitanvir, @User:DerHexer, @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 20:46, 12 December 2020 (UTC)

@Jdlrobson: FYI: I haven’t got any notification about this ping, except for the watchlist notification. No idea why. (By the way, the error appears to be because some users are loading the gadget using importScript(), and thus the CikkErtekelo object defined on hu:MediaWiki:Gadget-cikkertekeloCommon.js isn’t loaded. I’ll contact the affected users I can find when I have a bit more time.) —Tacsipacsi (talk) 16:33, 15 December 2020 (UTC)

8th December

Dear @User:Tuga1143, @User:Frokor, @User:Yair rand, @User:Akoopal, @User:js, @User:Od1n, @User:Holmium, @User:Axxgreazz, @User:РDD3, @User:MintCandy, @User:Ignatus, @User:Zanaq, @User:WhitePhosphorus, @User:Holek, , @User:Melderick, @User:Mizusumashi, @User:Chiefwei, @User:Mizusumashi, @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 20:11, 8 December 2020 (UTC)

@Jdlrobson: Are you running every script in the userspace ending in .js to check if they have errors? That sounds, ah, quite dangerous. Especially since some people might keep scripts in their userspace that edit pages as soon as run. Not everything there is intended to be a userscript that runs on every page load. (I was pinged about a script that was supposed to be run once from the console, not a regular userscript.) --Yair rand (talk) 21:38, 8 December 2020 (UTC)
User:Yair rand No I'm not running every script, gadgets personally scare me, so I don't run them for myself :). I'm generating these reports on the production errors being logged in our tool and prioritizing based on volume. I'm diving into the code and fixing some of the more high profile error causing scripts where I can, but trying to share the burden with people who know these scripts a little better. I think there is a lot of en:Cargo cult programming going on so definitely possible that people are including scripts as user scripts by mistake. If you see that happening, we have a useful tool on toolforge that should help finding those people. I've also found using `mw.notify` a good way to tell people to not do such things. Jdlrobson (talk) 23:06, 8 December 2020 (UTC)
Looks like User:Titodutta/global.js may be the source of this issue according to this search? Jdlrobson (talk) 23:08, 8 December 2020 (UTC)
Thanks, I've brought it up on the user's talk page. --Yair rand (talk) 23:13, 8 December 2020 (UTC)

29th November

Dear @User:Nesmir_Kudilovic, @User:MintCandy, @User:Frokor, @User:Euku, @User:Doc_Taxon, @User:1Veertje, @User:Axxgreazz, @User:Krassotkin, @User:Malarz_pl, @User:Holek, @User:Chiefwei, @User:Holmium, @User:1997kB, @User:Fagus, @User:ChP94, @User:Chiefwei, @User:User, @User:User, @User:User, @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 21:48, 29 November 2020 (UTC)

22nd November

Dear @User:Amorymeltzer, @User:Nesmir_Kudilovic, @User:Juan90264, @User:Frokor, @User:Cacycle, @User:Doc_Taxon, @User:Дима74, @User:Wcam, @User:User, @User:Euku, @User:Od1n, @User:Lupo, @User:Vlsergey, @User:Weltforce, @User:Abbas dhothar, @User:bluedeck, @User:Axxgreazz, @User:Xiplus, @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any.

17th November

Dear @User:STARSHIP_TROOPER, @User:Strangnet, @User:Martin_Urbanec, @User:PhiLiP, @User:Nesmir_Kudilovic, @User:GregorB, @User:Doc_Taxon, @User:Euku, @User:Jsimlo, @User:Cacycle, @User:Frokor, @User:Дима74, @User:Xaosflux, @User:Danmichaelo, @User:Holek, @User:Kwj2772, @User:Luizdl, @User:Vlsergey, @User:Neechalkaran, @User:Jon (WMF) apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 00:41, 18 November 2020 (UTC)

@Jdlrobson: I'm not even an admin on commonswiki, not sure why you keep pointing that one at me? — xaosflux Talk 02:10, 18 November 2020 (UTC)
@Jdlrobson: I don't understand, I'm not getting any error with my script, and no one that also use this script reported anything to me in my talk page. Which page have been thrown these errors?--Luizdl (talk) 03:43, 19 November 2020 (UTC)
If these logs say errors are occurring then I assure you they are. In terms of users not reporting them, I am guessing the errors are not obvious or impactful enough. The user might not realize the error is in the gadget if it's not loading and they are loading lots of other gadgets. Looking at the associated errors at least one of them relates to a race conditions: your script queries the variable `window.ve` but that will not exist unless the code inside the module
ext.visualEditor.ve
has alreadly loaded which isn't guaranteed in your script. When that happens the script will break before initializing. Looking at the script it would benefit from being wrapped inside a callback that guarantees VE has loaded:
mw.loader.using('ext.visualEditor.ve').then(function() {...})
.

In terms of others - on certain editing interfaces,

document.getElementById('wpMinoredit')

will return null so you'll need to check that. Not sure about the others without understanding your script better. Jdlrobson (talk) 06:27, 19 November 2020 (UTC)

How those logs are generated and where can I see them? I've changed if (window.ve.init) to if (window.ve && window.ve.init) so it wont throw null exception anymore because right side wont be checked, it is just to check if the edition is being made from text editor or 2017 wikitext editor, so if 've' is null then the edition was done from text editor. I've also change the part of getElementById('wpMinoredit') to check if the return is null, but which interface doesn't have wpMinoredit elememt (except anon user)?.--Luizdl (talk) 04:00, 22 November 2020 (UTC)

12th November

Dear @User:Phzh, @User:PhiLiP, @User:Trần_Nguyễn_Minh_Huy, @User:Danmichaelo, @User:Anomie, @User:bluedeck, @User:Strainu, @User:Dschwen, @User:Euku, @User:Cacycle, @User:Krassotkin, @User:Od1n, @User:Nesmir_Kudilovic, @User:РDD3, @User:User, @User:Strangnet, @User:GregorB, @User:Dbastro, @User:Jon (WMF) @User:Nadvšenec


Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 17:16, 11 November 2020 (UTC)

Hmm, my error is a bit complicated to solve without a backtrace. I tried a blind fix, feel free to ping again if still reproducible.--Strainu (talk) 18:27, 11 November 2020 (UTC)
@User:Strainu here is the stack trace:
at sanitizeForm 
at HTMLFormElement.<anonymous>
at HTMLBodyElement.dispatch
at HTMLBodyElement.elemData.handle
at performChanges
at URL3
at Object.success  URL3
at fire  URL2
at Object.fireWith [as resolveWith]
at done  URL2:129:95

Jdlrobson (talk) 15:57, 12 November 2020 (UTC)

  • This is an old version not used for a long time. Here is the current version. --sasha (krassotkin) 18:33, 11 November 2020 (UTC)
Thank you! Jdlrobson (talk) 15:57, 12 November 2020 (UTC)
I have no idea what is wrong on my side. If you can help, I am grateful. Kind regards, --Phzh (talk) 19:59, 11 November 2020 (UTC)
Have replied on your talk page Benutzer_Diskussion:Phzh/monobook.js. Jdlrobson (talk) 15:57, 12 November 2020 (UTC)

6th November

Dear @User:Skmp, @User:PhiLiP, @User:bluedeck, @User:Od1n, @User:Danmichaelo, @User:Frozen-mikan, @User:Cacycle, @User:Prolineserver, @User:Kwj2772, @User:Strainu, @User:Mardetanha, @User:bluedeck, @User:Trần_Nguyễn_Minh_Huy, @User:Doc_Taxon, @User:Zanaq, @User:-Kolossos, @User:Dschwen, @User:Strangnet, @User:Kibele, @User:Jon (WMF) Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 17:14, 6 November 2020 (UTC)

3rd November

Dear @User:Omar2040, @User:Skmp, @User:Prolineserver, @User:Lucas Werkmeister, @User:Cacycle, @User:Wanwa, @User:Amorymeltzer, @User:Zanaq, @User:Od1n, @User:MintCandy, @User:Mahir256, @User:PhiLiP, @User:Zanaq, @User:User, @User:JohanahoJ, @User:Euku, @User:Kwj2772, @User:GregorB, @User:TwinkleUser, @User:Jon (WMF)

Apologies for writing to you in English. I am currently trying to fix recurring errors in scripts across our movement concerning scripts on your projects.

Please see the most recent report of errors in gadgets and user scripts above and help me fix them. Please don't hesitate to ask questions if you have any. Jdlrobson (talk) 22:17, 3 November 2020 (UTC)

Jdlrobson: Thanks for the ping. Is it possible to get any additional information on where/when/what/etc. the errors are from? I'm obviously interested in Morebits, the one you've correctly pinged me for, and I know we can't get the stack trace, etc., but even just counts by wiki and/or day would be helpful. I do a lot of absurd breaking tests on test.wiki, and there are dozens of outdated installations around, so anything would help. Thanks for taking all this on! ~ Amory (utc) 22:33, 3 November 2020 (UTC)
So, this particular issue appears to be happening because people are loading the URL raw from other wikis like so:
mw.loader.getScript('https://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Twinkle.js&action=raw&ctype=text/javascript')

. Given this is an extremely popular script and the amount of errors here is high it seems like it would be helpful to help people set it up correctly by verifying dependencies at the top of the script and notifying the user they've set it up incorrectly in this case. e.g.

if(typeof Morebits === 'undefined') { mw.notify('Twinkle is not setup correctly.');}

Most of the errors appear to be coming from zh-yue.wikipedia.org - maybe zh-yue:MediaWiki:Gadget-Twinkle.js?

FYI: It looks like various people have also copied and pasted the script to local wikis and are having the same issue. For example User:Wikitanvir/twinkle/MediaWiki:Gadget-Twinkle.js and [[User:Frokor/twinkle.js] both throw the issue. These are both being loaded incorrectly so some safeguard in the Twinkle.js script checking it's been installed correctly would help (Assuming those changes propagate around the wikis). Jdlrobson (talk) 20:47, 4 November 2020 (UTC)

@Danmichaelo: Apparently there are some errors in d:User:Danmichaelo/Gadget-externalitemsuggester.js – I haven’t looked deeply into it, but it sounds like you need to ensure that some ResourceLoader modules are loaded. @Jdlrobson: I’m not sure why I’m getting pinged for user script errors? I’m not an interface admin on Wikidata, I couldn’t do anything about these errors even if I thought it was appropriate for me to edit Danmichaelo’s user scripts directly. --Lucas Werkmeister (talk) 22:03, 4 November 2020 (UTC)
there was a bug in the script. Thanks for flagging! It's only supposed to ping you about wikidata gadgets to help me find their maintainers. Jdlrobson (talk) 22:21, 4 November 2020 (UTC)
Thanks Jdlrobson for that info! Your fix on zh-yue is well done, although long-term they'll need to update that page entirely. Some changes to how Twinkle loads were made earlier this year, and while some projects engaged, some definitely did not! It can't be a major issue locally if nobody's complaining (then again I can't read so I wouldn't know...). I can (try) to engage with others if you like, but maybe see how much that changes things? ~ Amory (utc) 00:50, 5 November 2020 (UTC)

29th October

@User:Jvs, @User:Zuphilip, @User:OJJ, @User:Kacir, @User:HannaLindgren, @User:WikiUser22222, @User:Slomox, @User:Omar2040, @User:Skmp, , @User:Wanwa, @User:Prolineserver, @User:Lucas Werkmeister, @User:JohanahoJ, @User:Zanaq, , @User:Trần_Nguyễn_Minh_Huy, @User:Krzysiek_123456789, @User:Wargo, @User:PhiLiP, @User:Zanaq, @User:Fierodelveneto, @User:js, @User:TwinkleUser, @User:Vito Genovese, @User:Kwj2772, @User:Salam32, @User:Jon (WMF)

Jdlrobson (talk) 23:03, 29 October 2020 (UTC)

?? ꜰɪᴇʀᴏᴅᴇʟᴠᴇɴᴇᴛᴏ (Talk)-(Scrìvame in vec.wiki)-(Contributions) 23:05, 29 October 2020 (UTC)
There are some code issues with the gadget MediaWiki:Gadget-addsection-top.js that are described in the table above. Would you be able to find the appropriate person to fix these within the course of the next week? Jdlrobson (talk) 01:39, 30 October 2020 (UTC)
What problem is with "allinterwiki"? --Wargo (talk) 07:09, 30 October 2020 (UTC)
Good question. I took a look and it doesn't look like it should have any problems. The `SyntaxError: illegal character ` error usually means there is an invalid JavaScript character in the output e.g. a “ character but I don't see anything obvious. Perhaps a forced edit might clear out a badly cached version. All the production errors I am seeing come from Firefox and don't seem to be parsing the script correctly. I will remove it from future reports if it shows up again if we can't get to the bottom of this. Jdlrobson (talk) 23:23, 30 October 2020 (UTC)