13302296C / flutter_rte

Flutter HTML WYSIWYG rich text editor
MIT License
3 stars 7 forks source link

WEB: problem when working in iframe #5

Open NKoroloff opened 11 months ago

NKoroloff commented 11 months ago

Thanks for the plugin! but there is a nuance: when I build my project that works in an iframe, I get an error and nothing works, after debugging I came to the conclusion that this fix allows me to work normally.

PROBLEM CODE document.html ### line 58

/*---- Init Script ----*/
  document.addEventListener("DOMContentLoaded", function(event) {
    //here modified code which solves my problem (&& false)
    if (window.parent !== window.top && false){
      window.addEventListener('message', handleMessage, false);
    } else {
      window.parent.addEventListener('message', handleMessage, false);
    }
    document.onselectionchange = onSelectionChange;
  });

error image Can you help me figure out the problem?

pavel604 commented 11 months ago

Hey @NKoroloff , I understand you run your Flutter web app in an iframe. Unfortunately, the plugin relies on communication between the iframe and main window/tab. In this case, you get this error due to a nested iframe situation. If you don't target other platforms and this fix works for you, I would recommend to fork and tweak the plugin for your use case.

Have a look at this topic: https://stackoverflow.com/questions/11242074/how-to-access-nested-iframes

NKoroloff commented 11 months ago

can we add an optional property, for example, what iframe number should be opened for communication?

pavel604 commented 10 months ago

In theory - yes, but nesting iFrames is not something I would stand by. I'll mark it as an enhancement for potential future releases