WICG / portals

A proposal for enabling seamless navigations between sites or pages
https://wicg.github.io/portals/
Other
947 stars 66 forks source link

Is there a way to know whether the portal content is loaded #165

Closed juliadou closed 4 years ago

juliadou commented 4 years ago

After I create a portal with Site B in Site A, i would like to detect whether the portal content is loaded. Is there a way to achieve this?

I initially thought it could be achieved using messaging, but it seems only Site A can message the portal (Site B) and not vice versa.

lucasgadani commented 4 years ago

Both sites should be able to postMessage each other. From the portal host, you can use the HTMLPortalElement.postMessage() API. The other way around you need to use the portalHost interface, window.portalHost.postMessage().

The other option is to listen to the load event on the element. This can be done by listening to the HTMLPortalElement.onload event.

juliadou commented 4 years ago

Thank you! I tried portal.onload and it works great.

Regarding window.portalHost.postMessage, If I add it to Site B so Site B can post message to Site A, how can Site A receive the message? I tried to add window.addEventListener('message', callback) to Site A and it does not seem to work.

a4sriniv commented 4 years ago

The message gets dispatched on the portal element, so you need to use portal.addEventListener('message', callback').

domenic commented 4 years ago

This seems like a duplicate of #26, so I'll consolidate there. However it sounds like from @lucasgadani's comments Chromium implements the load event, so that's good input for #26 :).