Page MenuHomePhabricator

Page Previews: Instrumentation code throws syntax errors in older browsers
Closed, ResolvedPublic1 Estimated Story PointsBUG REPORT

Description

I noticed a spike in client-errors in Logstash that seem to be connected to our just-launched Mobile Page Previews experiment.

I was seeing thousands of JS errors with the following message:

SyntaxError: Failed to execute 'closest' on 'Element': '#mw-content-text a[href][title]:not(.extiw, .mw-selflink, .image, .new, .internal, .external, .mw-cite-backlink a, .oo-ui-buttonElement-button, .ve-ce-surface a, .ext-discussiontools-init-timestamplink, .cancelLink a, .mw-selflink-fragment, [href^="#"])' is not a valid selector.

In the instrumentation.js code for Mobile Page Previews, we have the following code:

// Track link clicks
// This mimics the logic in App.vue for which links to actually handle;
// other links (e.g. external) will not be tracked.
const selector = `#mw-content-text a[href][title]:not(${ excludedLinksSelector })`;

Then we do:

const link = event.target.closest( selector );

WMF staff can see the Logstash results here: https://logstash.wikimedia.org/app/dashboards#/view/AXDBY8Qhh3Uj6x1zCF56?_g=h@218e8f9&_a=h@9d755b9

Working theory

I believe that we are seeing these errors in browsers that don't support CSS selectors level 4 (2020-era browsers may lack this for example). See https://caniuse.com/css-not-sel-list

The problem is that we are calling :not() with a comma-separated list of selectors; older browsers can only accept a single (simple) selector here.

This matches what I'm seeing in the logs (Chrome v80 or below on older Android devices).

Proposed fix

We need to pass in a selectors-level-3-safe string that still implements all the desired behavior of the earlier L4 :not list.

Event Timeline

egardner raised the priority of this task from High to Unbreak Now!.
egardner set the point value for this task to 1.Apr 20 2026, 11:05 PM

Change #1275547 had a related patch set uploaded (by Jdlrobson; author: Eric Gardner):

[mediawiki/extensions/ReaderExperiments@wmf/1.46.0-wmf.24] [Mobile Page Previews] Avoid syntax error on older browsers

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

Change #1275547 merged by jenkins-bot:

[mediawiki/extensions/ReaderExperiments@wmf/1.46.0-wmf.24] [Mobile Page Previews] Avoid syntax error on older browsers

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

Mentioned in SAL (#wikimedia-operations) [2026-04-20T23:20:12Z] <jdlrobson@deploy1003> Started scap sync-world: Backport for [[gerrit:1275547|[Mobile Page Previews] Avoid syntax error on older browsers (T423959)]]

Mentioned in SAL (#wikimedia-operations) [2026-04-20T23:21:48Z] <jdlrobson@deploy1003> jdlrobson: Backport for [[gerrit:1275547|[Mobile Page Previews] Avoid syntax error on older browsers (T423959)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

matthiasmullie subscribed.

Confirmed fixed in logstash!