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

MathJax within JSXGraph iframes is not loaded via cors.php resulting in CORS error / broken math rendering #1340

Open
ngandrass opened this issue Dec 18, 2024 · 3 comments

Comments

@ngandrass
Copy link

Using MathJax within a JSXGraph applet does not render for me.

The JSXGraph applet is isolated within an iframe which is not able to load the required MathJax libraries due to CORS errors. JSXGraph itself is served via corsscripts/cors.php but MathJax is not.

MathJax is loaded as follows:

[[jsxgraph]]
    JXG.Options.text.useMathJax = true;
[[/jsxgraph]]

Used software:

  • Moodle: v4.5.1 (2024100701.01)
  • STACK: v4.8.1 (2024111900)
  • PHP: v8.2.26

How it looks inside the browser:
image

CORS errors:
image

Relevant HTML from the JSXGraph iframe:
image

Maybe related to #1160 since we are using a custom local path for loading MathJax instead of the CDN.

If you need further information or debugging let me know. Thanks a lot!

@EJMFarrow
Copy link
Collaborator

Hi @ngandrass,
It is related to custom local path for MathJax. Can you try changing the MathJax URL in local MathJax installation settings from a relative URL to the full URL, please? (Looks like it should be http://127.0.0.1/lib/mathjax/[email protected]/MathJax.js)
If that doesn't help, it may be an issue with using localhost. I'll investigate further.
Edmund

@aharjula
Copy link
Member

Note that we cannot, from the STACK side, control the headers of arbitrary addresses. So if you use a local MathJax coming from a custom URL you need to make sure that the webserve servers out those MathJax files with CDN like headers just like the cors-thingy we have for serving some of the other things going into the IFRAME but coming from our sources:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
header('Access-Control-Allow-Headers: *');

Those sandbox IFRAMEs require that those headers have been set. In most apache installs simply having in the MathJax folder a .htaccess rule like this does the trick, but having all three of the above ones makes things work with most things:

Header add Access-Control-Allow-Origin "*"

@ngandrass
Copy link
Author

ngandrass commented Dec 19, 2024

Thanks @EJMFarrow and @aharjula for your quick response!

Adding the Access-Control-Allow-Origin header indeed solves the problem for me 👍

For future readers that uses nginx, add the following to your config and replace /lib/mathjax/ with the path to your local location:

location /lib/mathjax/ {
    add_header 'Access-Control-Allow-Origin' '*';
}

However, I still wonder if it would be a good idea to handle the MathJax include via the already existing /corsscripts/cors.php. That would eliminate the need to alter the web server config. There even is a TODO comment in the respective function for it:

function stack_get_mathjax_url(): string {
// TO-DO: figure out how to support VLE local with CORS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants