I ended up doing the following, though Im sure it could be improved/done in a much better way
let svgReader = new FileReader();
svgReader.onload = function (e) {
let svg = $(e.target.result);
for(let i =0;i<svg.length;i++) {
if (svg[i] instanceof SVGElement) {
svg = $(svg[i]);
break;
}
}
let width = svg.attr("width");
let height = svg.attr("height");
if (height == null || height == undefined) {
svg.attr("height", 300);
}
if (width == null || width == undefined) {
svg.attr("height", 300);
}
let svgFile = new XMLSerializer().serializeToString(svg[0]);
let new file = new File([svgFile], files[index].name, {type: "image/svg+xml"});
};
svgReader.readAsText(files[0]);
I had to go through the SVG to find an instance of SVG element, as some of the SVGs I tested with had additional tags or comments that messed it up otherwise. Also, the 300 value for width and height was just made up, but seems to be ok, probably could have used the view box dimensions instead, but it works for me