simonhaenisch / md-to-pdf

Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
https://www.npmjs.com/md-to-pdf
MIT License
1.18k stars 111 forks source link

feature: ability to keep the browser window open (for testing & debugging) #283

Open zsolt-dev opened 9 months ago

zsolt-dev commented 9 months ago

Problem:

I use the programatic API to generate a PDF from a markdown variable. When I generate PDFs, it would help me to analyse the HTML and debug issues / play around in the browser devtools console.

But setting this just opens to browser for a split second.

launch_options: {
        headless: false,
        devtools: true,
}

Solution:

ability to provide a setting that would keep the browser open.

simonhaenisch commented 9 months ago

Sry for the late response due to sickness.

There's a --devtools CLI flag that does exactly this (without the headless: false which iirc is implied when devtools is enabled), and last time i tried it worked, but it's been a long while.

Just looking into it and I think the problem is that here it's checking only the config option but not the launch_options:

https://github.com/simonhaenisch/md-to-pdf/blob/7e0b9fc7a1209dc681903fab25f5af3a0551fd3a/src/lib/generate-output.ts#L104-L105

Should change this to access the property from the Puppeteer browser class I guess, but in the meantime you should be able to get it to work by setting devtools: true in the config that you pass to the mdToPdf function call.