neocotic / convert-svg

Node.js packages for converting SVG into other formats using headless Chromium
MIT License
200 stars 47 forks source link

Add puppeteer.launch options available into CLI #29

Closed leblanc-simon closed 6 years ago

leblanc-simon commented 6 years ago

You have added an awesome option into the API to customize puppeteer. This merge request try to allow use this option into the CLI

Example (because require escape JSON into the CLI... but I don't know how to do this without) :

./packages/convert-svg-to-png/bin/convert-svg-to-png --width 300 --puppeteer "{\"args\": [\"--no-sandbox\"],\"dumpio\":true}" *.svg
neocotic commented 6 years ago

@leblanc-simon First of all, thanks for your PR! This was a going to be a bit tricky, which is why I kept it separate from #25. I think you're right that a JSON string is the best option, at least initially. I had considered supporting individual options, however, type casting would quickly and easily become an issue.

If you're using Windows, you may have to escape the JSON as you have in your example, otherwise, you should be able to simply wrap the JSON using single quotes.

I'll try to take a deeper look and test this soon. Sadly, I still haven't got around to improving the testing framework to include CLI tests.

neocotic commented 6 years ago

I've just released v0.3.3 which includes this change. Thanks again for your PR.

leblanc-simon commented 6 years ago

Thanks ! I'm on Linux but I have some difficulties to escape JSON with simple quote. I'm lazy :) So when I found the good escape, I don't search any further

alohaninja commented 6 years ago

I had to use the same JSON escape sequence on Windows for Powershell...also disabling the GPU and sandbox setting to avoid the hang with Protocol error (Page.enable): target closed error.

It helped me to start with a simple puppeteer example. This ensures puppeteer is configured and running properly in your workspace.

Running Convert SVG in Powershell

convert-svg-to-png --puppeteer --% "{\"args\": [\"--disable-gpu\", \"--no-sandbox\"]}" .\example.svg