Skip to content

Conversation

@natebosch
Copy link
Member

@natebosch natebosch commented Jul 7, 2023

Originally the href was added manually to the data to work around a
dart:html limitation. A different workaround for the host side was
implemented in #2066, but the frame side was not changed in the same
commit to allow some cross-compatibility. Remove the final manual href
field now that no host implementations would read it.

natebosch added 2 commits July 7, 2023 00:30
Originally all communication was done through `postMessage` on the
`window`, but the manual checking between the `iframe.src` and the
iframe's `window.location.href` could go out of sync if the code under
test changed the browser location. To maintain the connection an
isolated `MessageChannel` was created for each frame, and only the port
for the channel was communicated across the window where the `href`
would need to be checked, but it was passed from the host to the frame
so the `origin` and `href` comparison was repeated on both sides.

Move the channel creation to the frame and send the port in place of the
old `'ready'` message. The ambiguous window level messages are now only
sent one direction, and only once. Immediately remove the window level
event listener for the individual frame once it has established the
channel (or reported an exception while loading). Drop the
`readyCompleter` and avoid subscribing to the channel local stream until
the iframe is ready and has sent a `MessagePort`.

Read the source from the message instead of sending the href in the
body. The linked issue (dart-lang/sdk#22554)
is only a problem when using `dart:html` which we no longer use. Since
not all message source types have a `location.href` property, use
`js_util.getProperty` which will return `null` when it is missing which
may be the case if some other source posts a message to the window
(which is not expected).

Drop the extra `_postParentMessage` definition, it became redundant when
migrating the other DOM interaction to static interop instead of
`dart:html`.
@natebosch
Copy link
Member Author

Flutter has an old copy of this code.

https://github.com/flutter/flutter/blob/2b6492426e5c9a17f3597f40323ce902d4540396/packages/flutter_tools/lib/src/web/bootstrap.dart#L248

If we make this change, when we roll package:test into the flutter repo we'll also need to adjust that.

cc @christopherfujino

@natebosch
Copy link
Member Author

This host <-> frame communication has been copied or reimplemented in a few places. Internal google code has a separate host implementations, and flutter_test has an implementation of the frame side.

I cannot land the change in flutter until the package is published to pub. I will not publish a change like this to pub until we have internal validation.

To resolve the deadlock I'm going to take a try at first implementing a backwards/forwards compatible host.dart.

@natebosch natebosch changed the title Overhaul the channel between host and iframes Remove unused href field from error report Oct 13, 2023
@natebosch natebosch closed this Oct 13, 2023
@natebosch natebosch deleted the single-message-on-outer-channel branch October 13, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants