Page MenuHomePhabricator

TypeError: Cannot read properties of null (reading 'getItem')
Closed, ResolvedPublicPRODUCTION ERROR

Description

2,532 errors in last 7 days
https://logstash.wikimedia.org/goto/0e0fe1dbc0d301785aa5718961e49fc2

Code path: https://gerrit.wikimedia.org/g/mediawiki/core/+/b31bb4715ca40f8ca79e0db16ae38471a4f2a922/resources/src/mediawiki.tempUserBanner/tempUserBanner.js#62
Introduced in 727b911c6995 (T344694)

Message:

TypeError: Cannot read properties of null (reading 'getItem')

Stack trace:

at shouldShowExpirationAlert  https://de.m.wikipedia.org/w/load.php?…&skin=minerva&version=wq1f2:1194:1023
at initTempUserBannerTooltip  https://de.m.wikipedia.org/w/load.php?…&skin=minerva&version=wq1f2:1196:639
at HTMLDocument.<anonymous>
at mightThrow
at process

Steps to replicate the issue (include links if applicable):

What happens?:

What should have happened instead?:

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Restricted Application changed the subtype of this task from "Bug Report" to "Production Error". · View Herald Transcript
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

@Sgs this error seems to be happening with quite high frequency. From user agents seems like it might be some kind of custom (albeit popular build)
Would be great to use mw.storage (mediawiki.storage) rather than localStorage directly as it has various other benefits.

A variation of this error is seen on authentication pages, as reported via the MediaWiki Platform Team's client error dashboard in Logstash, e.g. on https://auth.wikimedia.org/frwiki/wiki/Special:Userlogin?…&usesul3=1&useformat=desktop

NS_ERROR_FAILURE: 
at shouldShowExpirationAlert
at initTempUserBannerTooltip
at HTMLDocument.<anonymous>
at mightThrow
at process
resources/src/mediawiki.tempUserBanner/tempUserBanner.js#61
	function shouldShowExpirationAlert() {
		const tempUserExpirationAlertDismissed = localStorage.getItem( 'tempUserExpirationAlertDismissed' );

This is most likely because storage is full, unavailable, or denied for other reasons (i.e. private browsing, etc.).

As Jon says, localStorage should not be used directly in production code. Use mw.storage instead.

Change #1192868 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/core@master] tempUserBanner: make use of mw.storage instead of localStorage

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

Sgs edited projects, added: Growth-Team (Current Sprint); removed: Growth-Team.
Sgs moved this task from Incoming to Code Review on the Growth-Team (Current Sprint) board.

Change #1192868 merged by jenkins-bot:

[mediawiki/core@master] tempUserBanner: make use of mw.storage instead of localStorage

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

Michael added a subscriber: Dreamy_Jazz.

(Not sure if that should be checked by Growth QA, or maybe better by Trust and Safety Product Team / Product Safety and Integrity QA as the primary owners of the code touched here. Maybe @Dreamy_Jazz has thoughts?)

(Not sure if that should be checked by Growth QA, or maybe better by Trust and Safety Product Team / Product Safety and Integrity QA as the primary owners of the code touched here. Maybe @Dreamy_Jazz has thoughts?)

We have very limited QA capacity, and have been generally moving all our tickets to Done once the patch has been merged. As such, is there is space for Growth QA to look at this then I would suggest going that route. Otherwise, I would recommend just closing the ticket.

Michael renamed this task from TypeError: Cannot read properties of null (reading 'getItem') to TypeError: Cannot read properties of null (reading 'getItem').Oct 1 2025, 3:39 PM
Michael triaged this task as Medium priority.

This can now probably be closed as well. The frequency of this error has massively reduced in a way that lines up with when this change would have reached Group 2 wikis:

image.png (1,285×237 px, 25 KB)

While there are still instances of this error message occurring, they seem to have a different cause and should have a dedicated task if they are considered a priority.

@Krinkle and @Jdlrobson maybe we should have a mediawiki eslint rule for direct usage of localStorage ?