Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

convert-svg-core

neocotic34kMIT0.7.1TypeScript support: included

Supports converting SVG into another format using headless Chromium

convert, converter, svg, core, headless, chromium

readme

convert-svg-core

Build Status Downloads Release License

The core Node.js package for converting SVG into other formats using headless Chromium that contains the shared logic for all converters to support programmatic use. This package is not intended to be used directly to convert SVGs and, instead, provides core support for SVG conversion.

Install

If you are looking to install an out-of-the-box SVG converter, check out our converter packages below:

https://github.com/neocotic/convert-svg

Alternatively, if you know what you're doing, you can install using npm:

npm install --save convert-svg-core

You'll need to have at least Node.js v22 or newer.

If you're looking to create a converter for a new format, we'd urge you to consider contributing to this framework so that it can be easily integrated and maintained. Read the Contributors section for information on how you can contribute.

Implementation

To create a new SVG converter that uses convert-svg-core, you'll need to create a new subdirectory for your package under the packages directory. Try to follow the convert-svg-to-<FORMAT> naming convention for the converter package name.

Take a look at the other packages in this directory to set up the new package directory. They are all very similar, by design, as you should just need to provide the minimal amount of information required to support your intended output format.

Since this package only uses puppeteer-core, a Chromium instance must be provided and connected by the end user (e.g. using puppeteer to get an executable path).

Testing

Testing your SVG converter actually works is just as important as implementing it. Since convert-svg-core contains a lot of the conversion logic, a convert-svg-core-test package is available to make testing implementations even easier. Again, take a look at the tests for existing SVG converters under the packages directory for examples.

Environment

This package supports the use of a CONVERT_SVG_LAUNCH_OPTIONS environment variable to act as a base for the launch option passed to the Converter constructor. This can make it easier to control the browser launch/connection. For example;

export CONVERT_SVG_LAUNCH_OPTIONS='{"browser": "firefox", "executablePath": "/Applications/Firefox.app/Contents/MacOS/firefox"}'

Bugs

If you have any problems with this package or would like to see changes currently in development, you can do so here.

Contributors

If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!

A list of all contributors can be found in AUTHORS.md.

License

Copyright © 2025 neocotic

See LICENSE.md for more information on our MIT license.

changelog

Version 0.7.1, 2025.06.17

  • Allow import('puppeteer').executablePath to be passed directly in launch options to allow other launch options to be passed to it as a function
  • Document supported CONVERT_SVG_* environment variables
  • Document potential issues with reduced quality on macOS
  • Add Docker support for running the test suite on a Linux-based image
  • Bump all dependencies to latest versions

Version 0.7.0, 2025.06.14

  • Breaking Change: All packages now require Node.js v22 or newer
  • Breaking Change: Change createConverter to be async
  • Breaking Change: Rename Converter#destroy to Converter#close
  • Breaking Change: Rename puppeteer option to launch
  • Breaking Change: Change all convert-svg-to-<FORMAT> packages to only depend on puppeteer-core so consumers must depend on puppeteer and pass either a Browser instance via the browser option or LaunchOptions via the launch option to convert, convertFile, and createConverter functions
  • Breaking Change: Remove CLI support from all convert-svg-to-<FORMAT> packages and create new convert-svg-to-<FORMAT>-cli packages for that purpose (which come with puppeteer dependency to ensure browser is downloaded and installed for ease-of-use)
  • Rewrite the entire codebase in TypeScript and support both ESM and CJS usage
  • Add browser option to convert, convertFile, and createConverter functions to accept optional Browser instance
  • Add closeBehavior option to convert, convertFile, and createConverter functions to control the behavior when Converter#close is called
  • Add page option to convert, convertFile, and createConverter functions to accept optional options to be passed to puppeteer-core when creating a page
  • Add support for CONVERT_SVG_LAUNCH_OPTIONS environment variable to be merged with launch option
  • Change Converter to create and use BrowserContext per instance to use when opening new pages to ensure they are isolated and that they can be closed by the Converter accordingly
  • Change Converter#convert and Converter#convertFile to create a new temporary file and open a new Page per invocation to support safe concurrent invocations of these methods on the same Converter instance
  • Sanitize attributes on deeply nested SVG elements
  • Apply the round option to SVG width and height when applying the scale option
  • Improve documentation
  • Improve the developer experience for contributors with better tooling
  • Deprecate convert-svg-test-helper and create new convert-svg-core-test package as a replacement
  • Create new convert-svg-core-cli package to support CLI packages
  • Many internal changes to convert-svg-core
  • Bump all dependencies to latest versions

Version 0.6.4, 2022.06.07

  • Convert only first SVG element from input #86 2bbc498

Version 0.6.3, 2022.06.06

  • Retain only allowed attributes from SVG input #84 a43dffa

Version 0.6.2, 2022.05.29

  • Add convert-svg-to-webp package 812ea66
  • Strip onload attribute from SVG input #81 7e6031a

Version 0.6.1, 2022.04.29

  • Bump cheerio dependency to latest v1 RC avoid vulnerable dependency

Version 0.6.0, 2022.04.28

  • Breaking Change: All packages now require Node.js version 12.20.0 or newer
  • Support UTF-8 characters in SVG
  • Support SVG dimensions (width, height) that use pt units
  • Add rounding API and CLI option to control how dimensions are rounded (defaults to "round")
  • Fix CVE-2021-23631 by improving input validation
  • quality CLI option for JPEG not passed correctly #65
  • Bump dependencies (incl. major for Puppeteer)
  • Bump devDependencies
  • Skip inconsistent tests

Version 0.5.0, 2018.11.23

  • moved from !ninja to neocotic ad5aa55
  • modified CI to now target Node.js 8, 10, and 11 63fcb27
  • bump dependencies 6daedb1
  • bumped devDependenices 3a8ae85
  • fixed linting errors 96e7e06
  • fixed broken tests by regenerating expected fixtures bf34770
  • preventing lerna breaking build when calling "npm ci" on bootstrap 1391071
  • skipped tests that were causing CI build to fail intermittently cdf43c0

Version 0.4.0, 2018.02.05

  • Bump Puppeteer to v1 #32
  • Replace chai with assert #34

Version 0.3.3, 2017.12.08

  • Add puppeteer.launch options available into CLI #29

Version 0.3.2, 2017.11.21

  • Error being thrown caused by lost context for CLI #24
  • Pass custom arguments to puppeteer #25 #27
  • Bump puppeteer to v0.13.0 #26

Version 0.3.1, 2017.11.03

  • Error thrown as context is lost for API methods when using destructuring imports #22

Version 0.3.0, 2017.11.03

  • Add option to control background color #14
  • Remove all controllable short options for CLI #15 (breaking change)
  • Split package up into multiple packages to be more modular #17 (breaking change)
  • Add convert-svg-to-jpeg package to convert SVG to JPEG #18

Version 0.2.0, 2017.10.29

  • Add CLI & convertFile method to API #2 #8
  • Add scale option #3 #11
  • Throw error when baseFile & baseUrl options are both specified #4 (breaking change)
  • Change source/target terminology to input/output #6
  • Expose Converter class as primary export #9 (breaking change)

Version 0.1.0, 2017.10.19

  • Initial release