val image = js("""document.querySelector("iframe").contentDocument.querySelector("canvas").toDataURL()""")
console.log(image)
but this one fails with a ClassCastException:
Copy code
val image = ((document.querySelector("iframe") as HTMLIFrameElement)
.contentDocument?.querySelector("canvas") as HTMLCanvasElement).toDataURL()
console.log(image)
?
t
thana
09/16/2019, 5:35 PM
what i learned: never ever cast objets provided from "the outside js". in js objects mught look like or even behave like the objects you expect, but may not share the correct protoype that's used when transalteing a typecast to js
g
gaetan
09/16/2019, 5:41 PM
Thank you, I just needed your answer to remind me the unsafeCast function. This is working:
Copy code
val image = document.querySelector("iframe").unsafeCast<HTMLIFrameElement>()
.contentDocument?.querySelector("canvas").unsafeCast<HTMLCanvasElement>().toDataURL()
console.log(image)