0

I am using Dart 2 JS to execute Dart code in the browser.

There is an iframe element (src is of the same domain) in my HTML.
I want to use Dart to get the body of the html inside the iframe.

final iframes = document.getElementsByTagName('iframe').cast<IFrameElement>();     // Works
final iframe = iframes.first;     // Works
final bodyInsideIFrame = iframe.contentWindow!.document!.body      // Compile time error

This does not work. The contentWindow is WindowBase?, and not Window. This means there is not document property.

When I try to cast contentWindow to Window, I get the following error at runtime:

Evaluation failed: TypeError: Instance of '_DOMWindowCrossFrame': type '_DOMWindowCrossFrame' is not a subtype of type 'Window'

Note: I can get the Iframe's body easily with JS. So since it's possible with JS, I don't see why it would not be possible with Dart that compiles to JS (Dart 2 JS)

Flafy
  • 176
  • 1
  • 3
  • 15

0 Answers0