Server-side mermaid
Abstract
It would be better if graphs generated on server instead of client. Here are some possible implementations and "pro et contra" for them.
There are several possible solutions:
- JSDOM — doesn't supports
SVGTextElement.getBBox()
required by Mermaid. - PhantomJS/SlimerJS — dead
- puppeteer — only option except changing library (patch or switch to other one)
JSDOM
Original problem is that mermaid library uses DOM interfaces not only to get graph source text, but also to generate SVG elements. So we can add DOM implementation (aka pseudo-browser) and everybody will be happy...
Pro:
- No "heavy" dependencies (like browser installation)
- No platform-dependent dependencies (browser for windows/mac/... are very different beasts)
- No platform-dependent code (running browser process on windows/mac/... is very different beasts)
- Low: ,It requires pushing
window
anddocument
to global object, but it can be solved by VM or worker process.
Contra:
- It's not working, because mermaid requires
SVGTextElement.getBBox()
which is not implemented (and not easily implemented) in JSDOM.
PhantomJS
When alive mermaid-cli
used exactly this solution.
Pro:
- It's real browser (based on Chromium) with complete DOM.
- It's lightweight (contrary to other headless browsers) and not requires system installation.
Contra:
- It's not working, because it's duscontinued in 2016.
- "Heavy" binary dependencies (security problems)
- Binary dependencies (problems with cross-platform)
- External process (problems with rinning on different platform)
SlimerJS
Pro:
- It's API-compatible with PhantomJS, so
mermaid-cli
could be easily converted to use it. - It uses real browser (Firefox) with complete DOM.
Contra:
- It requires Firefox to be installed (system modification).
- It's not working, because it supports only Firefox 58 (released in 2018).
- "Heavy" binary dependencies (security problems)
- Binary dependencies (problems with cross-platform)
- External process (problems with rinning on different platform)
puppeteer
Pro:
- It's alive.
- It uses real browser (Chrome) with complete DOM.
Contra:
- It requires Chrome to be installed (system modification).
- "Heavy" binary dependencies (security problems)
- Binary dependencies (problems with cross-platform)
- External process (problems with rinning on different platform)
- Low: Has API other than phantomjs.