My app does the following:
- Load a 3rd party website using Node Request
- Inject a script in the html, which adds a listener to click events, to grab the text and put it in a custom dispatch event - eg. window.parent.document.dispatchEvent(clickedText)
- Puts this in an iframe on a page for the user. The parent window has a listener for these events, to then do things with that text.
This generally works fine. However... some websites never display as they get stuck trying to load resources that never arrive. And in rare occasions, a website seems to have some script which takes control of the parent page, and redirects it elsewhere.
I've tried adding a sandbox attribute to the iframe, which resolves both problems. But it then also blocks the dispatch event.
Is there a solution that will solve these problems, but still allow the iframe to send events to the parent window? I don't know a lot about iframe and cross-origin policy stuff, but I'm wondering if the iframe could talk to the node app, which the parent window could then request from node. No idea if that's possible though...