 <p>The webkit bug mentioned in @Phrogz answer seems to have been fixed in more recent versions, so I found a solution that doesn't require a manual parse is</p> <pre><code>// from http://bl.ocks.org/biovisualize/1209499 // via https://groups.google.com/forum/?fromgroups=#!topic/d3-js/RnORDkLeS-Q var xml = d3.select("svg") .attr("title", "test2") .attr("version", 1.1) .attr("xmlns", "http://www.w3.org/2000/svg") .node().parentNode.innerHTML; // from http://webcache.googleusercontent.com/search?q=cache:http://phpepe.com/2012/07/export-raphael-graphic-to-image.html // via http://stackoverflow.com/questions/4216927/problem-saving-as-png-a-svg-generated-by-raphael-js-in-a-canvas var canvas = document.getElementById("myCanvas") canvg(canvas, svgfix(xml)); document.location.href = canvas.toDataURL(); </code></pre> <p>which requires <a href="https://code.google.com/p/svgfix/" rel="nofollow">https://code.google.com/p/svgfix/</a> and <a href="https://code.google.com/p/canvg/" rel="nofollow">https://code.google.com/p/canvg/</a> and uses d3.js to obtain the svg source, which should be doable without d3.js as well (but this takes care of adding required metadata which can lead to problems when missing).</p>