:wave: Hello all! Has anyone used <DOMParser> to p...
# javascript
g
👋 Hello all! Has anyone used DOMParser to parse an HTML string in KotlinJS/Native? This fails for me in a
commonMain
module when I use as
val parser = DOMParser()
with this error
ReferenceError: DOMParser is not defined
. I've checked the docs and it looks like DOMParser should be part of kotlin-stdlib which should automatically be included in Kotlin Multiplatform projects. What am I missing? Thanks in advance 🙇
Based on answers here, I'm leaning towards it not being supported in NodeJS since it's more of a Javascript thing, rather than server-side
If this is the case, does anyone have a recommendation about a Kotlin library to parse HTML that can be used in multiplatform?
b
That API is part of stdlib, but is only available for js target as indicated by the yellow dot
That's why you can't use it in native or commonMain
g
Yep saw that now 🤦 I'll try to find another way but I suspect I'll most likely need custom bindings for a javascript library
I’ve found Skrape which might be what I’m looking for. Will give it a try.
b
But why? That still won't let you use it in common code
g
Yeah noticed that too after reading in more detail 😞 I'll give the node/js bindings a try as there's more libraries to choose from there
I ended up using node-html-parser and it works well with Kotlin bindings for nodeJs for anyone else landing here.