0

Disclaimer: this is my first time creating a chrome extension and I'm not very experienced with JS.

I have a contentscript that generates an XML string, and I want to prettify the string to make it easier to read. All other ways I found to do this, mess with the CDATA sections of the XML one way or another, so I figured I would use this npm module.

I have tried to import it in every way but can't get it to work. From what I saw the best way should be to add the script to the manifest in the web-accessible-resources, and then import it like so:

const src = chrome.runtime.getURL("xml-formatter-singleton.js");
const formatter = await import(src);
var formattedXmlString = formatter.formatXml(xmlString);
console.log(formattedXmlString);

What am I missing?

David
  • 1
  • 2
  • You need to use their distribution for the browser. It is not a ES module so don't use `import`, but simply add the name of the file at the start of `js` in your content_scripts declaration, then use the global `xmlFormatter` exposed by the script. – wOxxOm Apr 25 '23 at 08:21

0 Answers0