Any idea why this code works: ``` val image = j...
# javascript
g
Any idea why this code works:
Copy code
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
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
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)