I found if I call jQuery in global.js, ext.visualEditor.desktopArticleTarget.init may fail on Chinese Wikipedia. When it fails, my codes and gadgets on zhwp won't load anymore. Here is the error message:
/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:176 Exception in module-execute in module ext.visualEditor.desktopArticleTarget.init: Error: Bad constructor arguments Error: Bad constructor arguments at Uri (eval at <anonymous> (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:4), <anonymous>:127:715) at HTMLAnchorElement.eval (eval at <anonymous> (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:4), <anonymous>:438:45) at Function.each (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:5) at jQuery.fn.init.each (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:2) at HTMLDocument.eval (eval at <anonymous> (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:4), <anonymous>:438:21) at fire (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:45) at Object.add [as done] (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:45) at jQuery.fn.init.jQuery.fn.ready (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:49) at jQuery.fn.init (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:41) at jQuery (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:1)
However, it doesn't always fail. Sometimes everything is fine.
I replaced global.js with
$(function(){});
Errors still existed.
When I remove everything about jQuery in global.js, no errors occured.
Now I'm using
mw.loader.using('ext.visualEditor.core').always(function () { .... });
in global.js. No errors then.
Maybe T156899: VE should wait for global.js before init or T156346: VE plugins from user scripts suffer from race condition?
Other information:
- I use Firefox and Chrome
- While I'm finding errors, I disabled other gadgets and features on zhwp except VE and new wikitext editor.