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

πŸ’” GitHub Action Workflow fails to generate a PDF #97

Open
ebouchut opened this issue Nov 12, 2024 · 0 comments Β· May be fixed by #98
Open

πŸ’” GitHub Action Workflow fails to generate a PDF #97

ebouchut opened this issue Nov 12, 2024 · 0 comments Β· May be fixed by #98

Comments

@ebouchut
Copy link
Contributor

ebouchut commented Nov 12, 2024

Issue

When we click Resources β†’ PDF to open the PDF version of TrioDocs, we get a 404 error because the PDF file does not exist.
It has not been created.

A GitHub workflow fails to generate the PDF fails because it cannot load a font due to a CORS error.

Description

We use the mkdocs-exporter plugin to orchestrate the creation of the PDF.
Under the hood, it uses a Playwright Chromium headless browser to scour the website and compile the PDF.

❌ When processing a page with MathJax notation, the headless Web browser tries to load a Web font and refuses to do so because of a cross-domain request and we get a CORS error:

Access to font at 'https://unpkg.com/[email protected]/es5/output/chtml/fonts/woff-v2/MathJax_Calligraphic-Bold.woff' (redirected from 'https://unpkg.com/mathjax@3/es5/output/chtml/fonts/woff-v2/MathJax_Calligraphic-Bold.woff') from origin 'file://' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

To load the MathJax Javascript file, we use the MathJax URL mentioned in the mkdocs-material documentation:

https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

This generic v3 URL redirects to the current version (3.2.2) which is a different URL:

https://unpkg.com/[email protected]/es5/tex-mml-chtml.js

I don't think the redirection is posing a problem here.
This Javascript file is large (~1.2MB) because it is not minified.

Solution

I decided to use the minified version of the same file but hosted on Cloudflare instead of Unpkg:

https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.min.js
βœ… This fixed the issue.

Cause

My guess is that is due to Cloudflare using more permissive CORS server headers telling the server to allow the serving of fonts across domains, in our case from file://.

Access-Control-Allow-Origin "*"
@ebouchut ebouchut linked a pull request Nov 12, 2024 that will close this issue
ebouchut added a commit to ebouchut/trio-docs that referenced this issue Nov 12, 2024
No longer load Mathjax JS from Unpkg but Cloudflare.
This fixes nightscout#97 and loads a minified JS which is lightweight.
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

Successfully merging a pull request may close this issue.

1 participant