This PR adds proper browser part interop to the environment.
The browser part now has srcdoc property which is set as the underlying iframe's srcdoc attribute. And the window.message API allows for communication between the two.
The browser has a forward command which sends messages to the iframe.contentWindow (ie the srcdoc window). There the underlying running "app" can do whatever it needs with the message.
On the other hand the underlying srcdoc "app" can use the window.top.sendMessage api to send messages to the browser part. This is handled by System as here.
Main Points
This PR adds proper
browser
part interop to the environment.The
browser
part now hassrcdoc
property which is set as the underlying iframe'ssrcdoc
attribute. And the window.message API allows for communication between the two.The browser has a
forward
command which sends messages to the iframe.contentWindow (ie thesrcdoc
window). There the underlying running "app" can do whatever it needs with the message.On the other hand the underlying
srcdoc
"app" can use the window.top.sendMessage api to send messages to the browser part. This is handled by System as here.there is an example which you can import.
There are a number of things to notice here. In particular those mentioned in issues #141 and #142
The main fundamental change the addition of a
serialize=false
argument to the dynamic property value getter. And you can see it's use hereWe need this b/c otherwise the browser DOM parser will fail, stopping at the first
</script>
which just might be present in yoursrcdoc
.Similarly if you use a
field
part to write yousrcdoc
code *do not save it since it will not deserialize/parser property (again see #141).