Steps to replicate the issue
A recent uptick in client errors was caused by the following stack trace:
https://logstash.wikimedia.org/goto/edadec34a9c464c8faa71411bf2287c5
at initMediaViewer https://es.m.wikipedia.org/w/load.php?lang=es&modules=skins.minerva.scripts&skin=minerva&version=15hi7:7:317 at eval https://es.m.wikipedia.org/w/load.php?lang=es&modules=skins.minerva.scripts&skin=minerva&version=15hi7:12:62 at Object.fire https://es.m.wikipedia.org/w/load.php?lang=es&modules=mediawiki.base&skin=minerva&version=1hazk:4:699 at Object.<anonymous> https://www.mediawiki.org/w/index.php?title=XTools/ArticleInfo.js&action=raw&ctype=text/javascript:39:37 at fire https://es.m.wikipedia.org/w/load.php?lang=es&modules=jquery%2Cvue%7Cmobile.startup&skin=minerva&version=1y6cb:42:705 at Object.fireWith [as resolveWith] https://es.m.wikipedia.org/w/load.php?lang=es&modules=jquery%2Cvue%7Cmobile.startup&skin=minerva&version=1y6cb:43:903 at done https://es.m.wikipedia.org/w/load.php?lang=es&modules=jquery%2Cvue%7Cmobile.startup&skin=minerva&version=1y6cb:127:417 at XMLHttpRequest.<anonymous> https://es.m.wikipedia.org/w/load.php?lang=es&modules=jquery%2Cvue%7Cmobile.startup&skin=minerva&version=1y6cb:131:59
What happens?
While the root cause of this error is unknown, the error throws because $container[ 0 ] on the following lines in Minerva is undefined, which means the content container is empty.
mw.hook( 'wikipage.content' ).add( function ( $container ) { // If the MMV module is missing or disabled from the page, initialise our version if ( desktopMMV === null || desktopMMV === 'registered' ) { initMediaViewer( $container[ 0 ] ); }
What should have happened instead?
mw.hook( 'wikipage.content' ).fire is fired often enough that we can't guarantee it will return a DOM node.
We should validate that $container exists before calling initMediaViewer()
QA Requirements
The mobile site should not throw an error when a gadget uses the wikipage.content hook.
To simulate this situation, the following line can be executed in the browser console:
mw.hook( 'wikipage.content' ).fire( $( '#does-not-exist' ) );
The output of that line should not produce an error.