Page MenuHomePhabricator

TypeError: Cannot read properties of undefined (reading 'contains')
Closed, ResolvedPublicBUG REPORT

Description

Stack trace doesn't seem too helpful, but all the errors are occuring on the Special:ContentTranslation page. 177 errors in last 7 days, mostly on bn.m.wikipedia.org

https://logstash.wikimedia.org/goto/a3fccffca5300ff361e8b5b54261c269
https://logstash.wikimedia.org/app/discover#/doc/logstash-*/logstash-default-1-7.0.0-1-2022.11.16?id=wg_3f4QBkh1O0J80Lrar

Event Timeline

I've confirmed on the Logstash mediawiki-client-errors dashboard that message:"Cannot read properties of undefined" AND message:"contains" only has entries featuring error_context.skin:"contenttranslation". It is also specific to m-dot/MobileFrontend versions of that, with no entries from canonical domains.

Many indeed contain no stack trace other than HTMLDivElement eval. To see if there are entries from cache misses where there is a stack trace, I added AND NOT stack_trace:"HTMLDivElement" but that yielded zero results.

Without a stack trace, and no way to reproduce or assess user impact (if any), it might not be particularly actionable. In particular, as there are still numerous ways in which it might be noise caused by other software that happens to intersect with CX in which case we would never find the cause.

From experience, usually these limited stack traces point to issues inside event handlers at the top level entry file. Perhaps this is being used when there's no context. There's only a limited number of contains calls that need to be checked https://github.com/wikimedia/mediawiki-extensions-ContentTranslation/search?p=2&q=%22.contains%28%22 - if those all look good, we could put this down to a gadget as a lot of gadgets break on this page, as gadgets run inside ContentTranslation and often with the assumption they are running in Vector (not the special ContentTranslation skin).

If the issue is a call to classList.contains, it's possible that's being called on a Document or other element that does not implement Element e.g. document.classList.contains

Change 950196 had a related patch set uploaded (by Nik Gkountas; author: Nik Gkountas):

[mediawiki/extensions/ContentTranslation@master] SX: Check if target is of Element type before accessing classList

https://gerrit.wikimedia.org/r/950196

Change 950196 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] SX: Check if target is of Element type before accessing classList

https://gerrit.wikimedia.org/r/950196

Change 952858 had a related patch set uploaded (by Wangombe; author: Wangombe):

[mediawiki/extensions/ContentTranslation@master] CX3 Build 0.2.0+20230828

https://gerrit.wikimedia.org/r/952858

Change 954671 had a related patch set uploaded (by Nik Gkountas; author: Nik Gkountas):

[mediawiki/extensions/ContentTranslation@master] CX3 Build 0.2.0+20230904

https://gerrit.wikimedia.org/r/954671

Change 954671 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] CX3 Build 0.2.0+20230904

https://gerrit.wikimedia.org/r/954671

Change 952858 abandoned by Nik Gkountas:

[mediawiki/extensions/ContentTranslation@master] CX3 Build 0.2.0+20230828

Reason:

abandoning since we have already merged a newer build (I7d69dfb6c215a7769e74483bfa25d0b0ce2520a2)

https://gerrit.wikimedia.org/r/952858

This error was thrown for the cases described in T341562. Although the original issue described in that task has not been resolved, the error is now properly handled in production.

Screencast from greek (el) wiki, where no console error is thrown for "unselectable" sentences/paragraphs: