I have an addon (https://github.com/irvinm/Toggle-Native-Tab-Bar) that has an “options.html” which gives the user instructions and part of that is some CSS. I thought it would be nice to color code that CSS to make it more readable.
I didn’t want to do this step manually and looked into a library I could include that could take that HTML and format it. I ended up picking prism. (https://github.com/PrismJS/prism)
In my HTML, I initially had a block that looked like:
<pre>
<code class="language-css">
#main-window[titlepreface*=" "] #TabsToolbar {
display: none;
} </code>
</pre>
Prism.js uses the “language-css” class to determine how to return the CSS with proper CSS classes assigned to new spans. This all works well but when I was looking to submit this update to AMO, I got “Unsafe assignment to innerHTML” inside of Prism.js.
I looked into ways to resolve this and one way suggested was to use DOMPurify before calling innerHTML. However, when I tried this I got the same warning inside of DOMPurify.
I am not that experienced with JS and not sure how to proceed. Any suggestions would be appreciated. (In the short term, I have taken the returned HTML and just hard-coded that into options.html and removed Prism.js from the project for now. Obviously, I would prefer to leave it dynamic in case I need to change and\or add more CSS text)
Mozilla security page with reference to DOMPurify as well: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Safely_inserting_external_content_into_a_page