Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add try/catch around do_user_agent_identification(); [was: Should stop relying on navigator.appVersion] #1155

Closed
berdario opened this issue Apr 9, 2015 · 18 comments
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Not Needed v2.6
Milestone

Comments

@berdario
Copy link

berdario commented Apr 9, 2015

From MDN

Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

And indeed this is starting to cause problems on my Firefox 37, Ubuntu. I have the following navigator.appVersion:

"5.0 (X11)"

For comparison, on Chrome it's:

"5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"

This causes a TypeError: navigator.appVersion.match(...) is null

I assume at this line: (navigator.appVersion.match(/WebKit\/(\d+)\./)) [1] (unfortunately the sample uses the minified mathjax, and thus it's not so simple to discover where it's failing)

@pkra
Copy link
Contributor

pkra commented Apr 10, 2015

Putting aside the (eternal) discussion about browser sniffing, I'm not seeing any errors on FF 37.0.1, ubuntu 14.10. Do you get the error when visiting that particular sample?

@berdario
Copy link
Author

Yes

Apparently the issue is slightly more complex: that issue affects Firefox 37 on Ubuntu 15.04 (which is in late Beta after Kernel Freeze, a few days before the RC), but now I tried to reproduce it again on Ubuntu 14.10, and MathJax works just fine.

Moreover, navigator.appVersion on Ubuntu 14.10 is

 "5.0 (X11)"

Which is exactly the same as on Ubuntu 15.04, so I'm quite stumped. :/

@pkra
Copy link
Contributor

pkra commented Apr 10, 2015

Thanks for following up on this. That's rather strange. I'll try to reproduce this on a clean 15.04 VM.

@pkra
Copy link
Contributor

pkra commented Apr 10, 2015

Hm. I spun up the daily build live CD of Ubuntu Gnome. It ships Firefox 37.0.0 and does not show any trouble. Do you have any extensions installed that might interfere?

@berdario
Copy link
Author

No extensions enabled except the default Ubuntu ones, I even reproduced the issue by running Firefox in Safe Mode

@dpvc
Copy link
Member

dpvc commented Apr 10, 2015

@berdario, the line you indicate should only be executed by WebKit browsers, so shouldn't apply to Firefox. What is your navigator.userAgent set to?

@berdario
Copy link
Author

Ugh, you're right... it was

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36

Turns out that in 2015 there are still some websites that do user agent filtering to prevent access to websites, I tweaked it some time ago and then forgot about it -_-

I guess that on one hand this could be filed under PEBKAC, but otoh, it'd be better if the user-agent sniffing code was a bit more robust... by looking at the code it's just mostly used to identify the exact version of the browser. If it's not critical for MathJax behavior I guess a simple

try {
  do_user_agent_identification();
}
catch (e) {
  HUB.Browser.version = 'unknown';
  console.error(e);
}

Might be good to add

Anyhow, before looking again at this, I was trying to run MathJax in development mode (that is, without packing everything), but I couldn't find any instructions in the documentation (it expects me to use the prebuilt MathJax/MathJax.js which is not useful when narrowing down such issues)...

Not even CONTRIBUTING mentions how to run it in dev mode... is it possiible to add a couple lines?

@pkra
Copy link
Contributor

pkra commented Apr 13, 2015

For the code suggestion, @dpvc what are your thoughts?

For the documentation part, it's a long standing issue that we don't have good documentation for developers (for mainly historic reasons). I've opened #1162 and mathjax/MathJax-docs#100

@dpvc
Copy link
Member

dpvc commented Apr 13, 2015

I don't have a problem with putting a try/catch around the relevant code.

@pkra pkra added Accepted Issue has been reproduced by MathJax team and removed Investigate labels Apr 15, 2015
@pkra pkra changed the title Should stop relying on navigator.appVersion add try/catch around do_user_agent_identification(); [was: Should stop relying on navigator.appVersion] Apr 15, 2015
@pkra pkra added this to the MathJax v2.6 milestone Apr 15, 2015
dpvc added a commit to dpvc/MathJax that referenced this issue Apr 15, 2015
@dpvc
Copy link
Member

dpvc commented Apr 15, 2015

Ok, I've added this in the issue1155 branch of my fork of MathJax.

@dpvc
Copy link
Member

dpvc commented Apr 21, 2015

==> Merged

@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Apr 21, 2015
@dpvc dpvc closed this as completed Apr 21, 2015
@dpvc dpvc added v2.6 Fixed and removed Fixed Merged Merged into develop branch labels Jan 2, 2016
@arvindpdmn
Copy link

arvindpdmn commented Apr 17, 2020

I'm getting the navigator null error on Firefox 75.0 (64-bit) on Windows 10. I'm using MathJax 2.7.8.

I then tried 2.6.0, the version when it was fixed. But with this version I get the following error:

The resource from “https://cdn.jsdelivr.net/npm/mathjax@2.6.0/MathJax.js?config=TeX-MML-AM_CHTML” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).

@dpvc
Copy link
Member

dpvc commented Apr 17, 2020

@arvindpdmn, I am not able to reproduce your problem. Firefox 75 works fine for me on Windows 10. Can you give the actual error message that you are receiving?

As for 2.6.0, it appears that there is no npm package for that version (but there is for 2.6.1). You can see the versions that npm has available using the versions tab here.

You can get 2.6.0 from GitHub instead, using

https://cdn.jsdelivr.net/gh/mathjax/mathjax@2.6.0/MathJax.js?config=TeX-MML-AM_CHTML

if you wish. The reason you are getting the error message you indicated for this (about text/plain) is that jsdelivr returns an error page for version 2.6.0 that is a plain text page, rather than the javascript that the browser was expecting.

@arvindpdmn
Copy link

I'm not able to reproduce the problem today! There's no error on Firefox 75 on Windows10 on 2.7.1, 2.7.8 or 2.6.1.

The error message I was getting yesterday with 2.7.1 via Cloudflare (or 2.7.8 via jsdelivr.net):

navigator.appVersion.match(...) is null MathJax.js:19:61918
    <anonymous> https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML:19
    <anonymous> https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML:19

Perhaps something in my code was triggering this. Need to look into this later.

@dpvc
Copy link
Member

dpvc commented Apr 18, 2020

There is only one line where this could be coming from, and that is in the handling of the Safari browser. That suggests that there is something strange about the browser string that you are using. What is the value of navigator.appVersion (enter that in the browser console and see what it produces)?

Also, what is the value of MathJax.Hub.Browser? It is a string object with additional properties, so be sure to open the object to see something like this:

browser

In any case, all of the navigator.appVersion references are now inside a try/catch structure (which was the subject of this issue tracker), and the catch simply prints the error message, so that message is informational and should not prevent MathJax from running.

@arvindpdmn
Copy link

On Firefox 75, navigator.appVersion gives me "5.0 (Windows)"

For MathJax.Hub.Browser, see attachment:
ff-mathjax

@dpvc
Copy link
Member

dpvc commented Apr 18, 2020

OK, thanks. That all looks as it should. Can you use

https://cdn.jsdelivr.net/npm/mathjax@2.7.8/unpacked/MathJax.js?confg=TeX-MML-AM_CHTML

(not the unpacked/ in the URL), as that will get a better stack trace, and report the error message and stack trace again?

@arvindpdmn
Copy link

But I don't get any error today like I did yesterday. However, I will use the unpacked/ version should the error occur again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Not Needed v2.6
Projects
None yet
Development

No branches or pull requests

4 participants