Closed zacharysyoung closed 2 weeks ago
Two possible things that might help you:
If you're comfortable with Node.JS, you could write a Node.JS script that creates a single Puppeteer/Chromium instance, and then run mermaid-cli
on it.
E.g., something like:
import {writeFile} from 'node:fs/promise';
import puppeteer from 'puppeteer'
import { renderMermaid } from '@mermaid-js/mermaid-cli';
// single instance of Chromium
const browser = await puppeteer.launch();
async function main() {
while (true) {
// run renderMermaid as many times as you want, they'll all share the same browser instance
const { data } = await renderMermaid(browser, myMermaidCode, 'png');
await writeFile(data, 'my-output-file.png');
}
}
main();
@mermaid-js/mermaid-cli
uses a pretty old version of Puppeteer, in order to support an old version of Node.JS. You can try using npm install github:aloisklink/mermaid-cli#v11
(or npx github:aloisklink/mermaid-cli#v11
), which will install the version in https://github.com/mermaid-js/mermaid-cli/pull/701, which has a much more modern version of Puppeteer.@aloisklink, thank you very much for both recommendations. I tried both and ran into issues with each:
Either seems reconcilable, but at this point I'm happy to just accept the ~2s run time: it was more a matter of principle ("there's got to be a better/faster way!") than anything practical.
I really appreciate your help so far, but I don't need to pursue this any further. :)
I've also made my own just-SVG cli.
Describe the bug I'd like to start Chromium and just have it running in the background and specify that puppeteer connect to that instance, to reduce startup time and increase processing speed.
I've tried supplying browserWSEndpoint, or the newer browserUrl, both from the ConnectOptions interface, but mmdc doesn't seem to respect them.
To Reproduce Steps to reproduce the behavior:
I started the packaged Chromium:
or,
Expected behavior I'm not sure what I should see, but I believe seeing another instance of Chromium running on a different port indicates that mmdc or puppeteer doesn't know about my already-running instance.