isomorphic-dompurify icon indicating copy to clipboard operation
isomorphic-dompurify copied to clipboard

Web Worker Support

Open wSedlacek opened this issue 2 years ago • 3 comments

Web Workers resolve to the browser.js however window is not defined thus causing an undefined reference. Using globalThis or self instead of window could allow this file to work in web workers too.

Uncaught ReferenceError: window is not defined
    at node_modules/.pnpm/[email protected][email protected]/node_modules/isomorphic-dompurify/browser.js (isomorphic-dompurify.js?v=650fd638:949:22)

wSedlacek avatar Dec 26 '23 16:12 wSedlacek

Hey @wSedlacek , Thanks for reporting this issue. Would you like to work on a solution?

kkomelin avatar Dec 27 '23 02:12 kkomelin

Sure! I would be happy to make a PR. I need to know the supported browsers to know if globalThis is the best solution (or if typeof window === undefined would be better)

wSedlacek avatar Dec 27 '23 15:12 wSedlacek

Great news @wSedlacek. We've recently switched to typeof window !== 'undefined' https://github.com/kkomelin/isomorphic-dompurify/releases/tag/v2.0.0 for the server-side version, so I think it would be ideal if we could use the same for the client one.

kkomelin avatar Dec 28 '23 04:12 kkomelin