I'm working with lightning web components (lwc) from Salesforce.
I'm trying to load this library as Static Resource to use it in one of my components, in order to sanitize some data -> DOMPurify . I'm using just the min js file.
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
import DOMPURIFY from '@salesforce/resourceUrl/DOMPurifyMin'
export default class classNameHere extends LightningElement {
DOMPurifyInitialized = false
renderedCallback() {
if (this.DOMPurifyInitialized) {
return;
}
this.DOMPurifyInitialized = true;
Promise.all([
loadScript(this, DOMPURIFY)
])
.then(() => {
this.initDOMPurify()
})
.catch((error) => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading this',
message: error.message,
variant: 'error'
})
);
});
}
initDOMPurify() {
console.log('inside initDom')
console.log(DOMPurify.sanitize(`<img src=x onerror=alert(1)//>`))
}
}
I can reach initDOMPurify, but then it fails in that second console.log() that uses DOMPurify.
Error message in catch block: Failed to execute 'createNodeIterator' on 'Document': parameter 1 is not of type 'Node'.
Any ideas? I haven't found much information about this kind of error.