Page MenuHomePhabricator

TypeError: Cannot read properties of undefined (reading 'replace')
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
TypeError: Cannot read properties of undefined (reading 'replace')
exception.trace
at HTMLDocument.<anonymous>  <anonymous>:7:115
at mightThrow  https://zh.wikipedia.org/w/load.php?lang=zh-cn&modules=jquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.ui&skin=minerva&version=9n6gj:49:833
at process  https://zh.wikipedia.org/w/load.php?lang=zh-cn&modules=jquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.ui&skin=minerva&version=9n6gj:50:498
Impact

297 in last 12 hours. Affecting zh.wikipedia.org and ru.wikipedia.org.

Notes

Event Timeline

Krinkle claimed this task.
Krinkle added subscribers: WhitePhosphorus, Krinkle.

Without a team or component tag this task would likely be ignored indefinitely, except for weird people, like me :)

I looked through a dozen or so matching rows on the mw-client-errors dashboard in Logstash and found that:

  • The entry linked in the task description by @nray reports a pageview URL, but most entries for this error have aa Special:ContentTranslation URL. Visiting one of the CX links as-is seems to cause a different error: TypeError: firstHeadingNew is undefined , which comes from zhwiki's site module (Common.js), and is filtered out on the dashboard as matching the stack trace for eval'ed user script code.
  • Visiting the linked entry's pageview URL as-is with my logged-in account in Firefox did not reproduce any error.
  • All rows have the exact same stack trace. This is significant because usually when a stack trace is as short and generic as this one, it indicates that code was cached, and thus there is hopefully also an instance of the error on a cold pageview with more details available. There might be such a log entry, but there wasn't one in the samplings I inspected. One thing to note is that HTMLDocument means an inline script was used. We use dynamic inline scripts for cached code execution, but a more common use of inline scripts is CentralNotice banners. I ran through the currently active campaigns and did not find code involving .replace( in those banners, and also did not experienc the error emperically when browsing through several random pages and the randomly picked banners.
  • The subset of log entries that came from pageviews, all had resource URLs with useskin=minerva and used Chrome (not Firefox). Opening a random article with useskin=minerva in Chrome (logged-out) reproduced the issue. Breaking on the uncaught error lead to zhwiki's the code of the "site" module (alternatively, use debug mode to get a more useful URL). This is the same code as we found in the first bullet point, but reported differently.

It seems in Firefox the error is reported as:

TypeError: firstHeadingNew is undefined

And the part that isn't asynchronous, has a stack trace mentioning domEval, which mw-client-errors filters out as relating to user/site scripts.

In Safari as:

TypeError: undefined is not an object (evaluating 'firstHeadingNew.replace')

In some older Chrome versions as:

TypeError: Cannot read property 'replace' of undefined

In the latest Chrome as:

TypeError: Cannot read properties of undefined (reading 'replace')

Long story short: zhwiki has some Common.js code that only works in Vector. It breaks in Minerva and custom pages due to these layouts being unusual in not having any [id="firstHeading"] element.

The code was introduced on-wiki two days ago by @WhitePhosphorus as "workaround for T294612", in revision 68463844.