Modify SVG and export it as SVG

Hi, I am trying to read an SVG file in a container field and do some modifications in Web Viewer. Here is my code. I have base64encoded the SVG file and pass to web viewer.

window.changeColor = async (json, color) => {
  const svg = atob(json);
  let container = document.getElementById("container");
  container.innerHTML = svg;
  let svgicon = document.querySelector("svg");
  svgicon.setAttribute("fill", color);
  svgicon.setAttribute("class", "fm_fill");
  const blob = new Blob([svgicon], {type: "image/svg+xml"});
  blobToBase64(blob).then((svg) => {
    FileMaker.PerformScriptWithOption("Get SVG", svg, 5);
  });
}

I have tried to change the SVG in base64 format and pass it back to FM when I exported it, it said there is an error on line 1.

Does anyone know how to do that? Thank you.