Page MenuHomePhabricator

Unable to view and navigate images on certain pages in MultimediaViewer: TypeError: Cannot read property 'protocol' of undefined
Closed, DuplicatePublic

Description

VM204:212 Uncaught TypeError: Cannot read property 'protocol' of undefined
    at new Uri (<anonymous>:212:538)
    at ViewLogger.VL.recordViewDuration (VM208 load.php:3)
    at VM208 load.php:4
    at dispatch (VM199 load.php:69)
    at elemData.handle (VM199 load.php:66)
  • Click on map in top right corner
  • Press "right" arrow
Uncaught TypeError: Cannot read property 'protocol' of undefined
    at new Uri (<anonymous>:212:538)
    at ViewLogger.VL.recordViewDuration (load.php?lang=en&modules=mmv&skin=vector&version=1e2u5:3)
    at MultimediaViewer.MMVP.loadIndex (load.php?lang=en&modules=mmv&skin=vector&version=1e2u5:106)
    at MultimediaViewer.MMVP.nextImage (load.php?lang=en&modules=mmv&skin=vector&version=1e2u5:106)
    at LightboxInterface.OO.EventEmitter.emit (<anonymous>:250:483)
    at CanvasButtons.OO.EventEmitter.emit (<anonymous>:250:483)
    at HTMLButtonElement.<anonymous> (load.php?lang=en&modules=mmv&skin=vector&version=1e2u5:57)
    at HTMLButtonElement.dispatch (load.php?lang=en&modules=jquery&skin=vector&version=tqh7e:69)
    at HTMLButtonElement.elemData.handle (load.php?lang=en&modules=jquery&skin=vector&version=tqh7e:66)

Event Timeline

Usually these are due to manual writing of bad URLs or due to broken user scripts creating bad URLs. But, in this case it is not.

I can confirm that when reading this article normally (no fragment), and then clicking on the second image, it fails the same way.

This means MediaViewer itself is creating these URLs in an invalid way, not escaping them correctly. That probably causes other issues as well, but none as obvious/easy to find as this one.

Aklapper renamed this task from Unable to view and navigate images on certain pages in MultimediaViewer without error to Unable to view and navigate images on certain pages in MultimediaViewer: TypeError: Cannot read property 'protocol' of undefined.Nov 24 2020, 7:23 AM

URI encoding errors originating from multimedia viewer account from one our top ten errors (URIError: malformed URI sequence + Uncaught URIError: URI malformed) so marking this as high.
There is a danger these errors will increase as we roll out error logging to more of our sites.

Managed to find that, at least on simple.wikipedia.org, the URL in question is "/beacon/media", which is being passed into the mw.Uri constructor unmolested. Not terribly ideal, so I suppose we should de-relativize it before passing it into mw.Uri. Might be a nice-to-have if mw.Uri handled relative URLs in the future but I think hardly a necessity.

Indeed, it seems this value is the default, and no overrides are set in the wmf-config files, so rolling out logging will likely flood us with errors.

I'll shop this around a little bit and see what we can do on the not-multimedia team, though our time seems to be at more and more of a premium lately.

Ignore the above, it was typed when I had but dreamt of having my morning coffee.

The malformed URI error occurs when parsing location.href to get the default URI for handling relative URLs, which mw.Uri does just fine as long as we aren't passing it a default URI that has an unescaped percent sign ('%') in it, I imagine.

So yeah, as Krinkle says, we have some escaping to do in MMV, sorry about pointing the finger at the wrong code there.

Change 647676 had a related patch set uploaded (by Cparle; owner: Cparle):
[mediawiki/extensions/MultimediaViewer@master] url-encode page uri before starting the view duration timer

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

Change 647676 merged by jenkins-bot:
[mediawiki/extensions/MultimediaViewer@master] url-encode page uri before starting the view duration timer

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

Thanks for looking into this one!

Change 668495 had a related patch set uploaded (by Jdlrobson; owner: Jdlrobson):
[mediawiki/extensions/MultimediaViewer@master] Catch malformed URIs

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

Change 668495 merged by jenkins-bot:
[mediawiki/extensions/MultimediaViewer@master] Catch malformed URIs

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