MathJax 3 completion handler fails if the content contains processing instructions
Created by: bthomale
Issue Summary
We found a bug where, when using tex-mml-chtml conversion, if the input file is xhtml containing a processing instruction, the completion handler never fires. Additionally, the javascript will show the following error in the console:
Unhandled Promise Rejection: TypeError: t.getAttribute is not a function. (In 't.getAttribute(e)', 't.getAttribute' is undefined)
We've replicated this in WebKit / Safari on macOS, iOS. And also in the embedded webkit view in Android.
Essentially, it's iterating through the content looking at the "class" attribute of various nodes. Somehow it is assuming they're all elements, and when it hits a processing instruction node (where getAttribute is not defined) it throws this error. You can see exactly what is happening if you turn on "break on exceptions" in the WebKit debugger.
We noticed that it only happens during TEX input processing, which we don't need. Turning off TEX works around the problem, which is what we have done. But it's still a bug, so I thought you might be interested in looking at it.
I've included 3 different versions of the file to illustrate this:
- tex-mml-chtml-with-pi.xhtml
This is the one that fails. It has a completion handler defined that logs "done" to the console. If you open up the console you'll see the error I described, and "done" is never logged.
- tex-mml-chtml-no-pi.xhtml
This illustrates that without the pi the example completes successfully and logs "done" to the console.
- mml-chtml-with-pi.xhtml
This illustrates that with the pi, but with mml-chtml ONLY (no TEX) it also completes successfully and logs "done" to the console.
Steps to Reproduce:
- Open the attached file tex-mml-chtml-with-pi.xhtml
- Open the debug console
- Refresh the page. You'll see the error and that "done" is never logged.
Technical details:
- MathJax Version: 3.1.2
- Client OS: macOS 11.2.3
- Browser: Safari 14.0.3
^ I was able to replicate with that. Easier than trying to reproduce with mobile.
Supporting information:
See the above attached zip for the promised example files. Just open them in Safari.