-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core(oopif): attach to all descendants #7608
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is dope. nice work sorting all this out
DZL, do a barrel roll |
DZL is done! Go check it out http://lh-dzl-7608.surge.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice and clean solution! Going to be a little hard to reason about how it works a month or two from now, but that seems pretty inherent to what we have to do to make it work :/
Not-directly-this-PR-related thoughts:
-
I think we should consider splitting driver in the near future, like we've talked about a few times. This PR could make a nice split point, wrapping
connection
as it's passed into the constructor with amultiTargetConnection
that hides this logic inside -
I'm a little concerned about the scalability of handling each type of
Target
message passed up individually, so we should think about what we want to do (transparent like theseNetwork
events? And/or some kind of explicit session handling for gatherers that want to ask a particular target a question?).Not just academic, @paulirish is already talking about injecting some code in there to do some SW shenanigans 😭
this._handleTargetAttached(protocolMessage.params, sessionIdPath); | ||
} | ||
|
||
if (protocolMessage.method.startsWith('Network')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emit this one so it's handled as usual instead of handling it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well our current handling isn't actually on driver events it's off the connection event, and I thought it would be weird to forcibly emit an event from within driver on the connection. but I guess you disagree?
🤞 hopes the answer isn't let's refactor this whole thing now ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compromise: moved this bit into a function that gets called by both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well our current handling isn't actually on driver events it's off the connection event
ah, I had forgotten about this. I also remembered we did it the way it is because you can't listen to Network.*
, so we needed to listen to protocolevent
, which is too bad.
moved this bit into a function that gets called by both?
sounds perfect
lighthouse-core/gather/driver.js
Outdated
|
||
// We receive messages from the outermost subtarget which wraps the messages from the inner subtargets. | ||
// We are recursively processing them from outside in, so build the list of parentSessionIds accordingly. | ||
const sessionIdPath = parentSessionIds.concat([sessionId]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just push()
like normal people :P
(also, if we're only ever going to look at it in reverse order, unshift()
and remove the reverse()
instead?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you think a normal person would prefer a list that's mutated through these layers on top of everything else that's going on!?! 😱
you feelin' alright @brendankenny? you might want to go to a doctor to get that checked out 😛
the reverse point is worth discussing though :)
IMO, it's easiest to keep track of what the list looks like based on how it's being built, not how it's being used. This way you do not need to be thinking about the complexities of another function just to understand what's going inside this one. The fact that it gets used to build the messages inside out is an implementation detail of its sibling function (afterall I could have written sendMessageToTarget in a recursive way in which case the list wouldn't need to be reversed). WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you think a normal person would prefer a list that's mutated through these layers on top of everything else that's going on!?! 😱
lol, I forgot about that benefit of concat
:P :P
IMO, it's easiest to keep track of what the list looks like based on how it's being built, not how it's being used.
i mean, [sessionId, ... parentSessionIds]
doesn't seem any more surprising to me than the other way around, honestly. I do find
The fact that it gets used to build the messages inside out is an implementation detail of its sibling function (afterall I could have written sendMessageToTarget in a recursive way in which case the list wouldn't need to be reversed).
compelling, but I think the justification works for either approach (if _handleReceivedMessageFromTarget
was written differently :). The main downside of the current approach is the .slice().reverse()
, which adds mental overhead to the code we actually have written
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you had me at [sessionId, ...parentSessionIds]
:) done
@@ -5,6 +5,6 @@ | |||
</head> | |||
<body> | |||
<h1>Hello frames</h1> | |||
<iframe name="oopif" src="https://airhorner.com"></iframe> | |||
<iframe name="oopif" src="https://www.paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/" style="width: 100vw; height: 100vh;"></iframe> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, should we just be making our own OOPIF here rather than relying on this page having another nested one? We could do a page on the other port to go cross origin (assuming that triggers OOP) and have that embed the youtube video, for instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish, I tried like 15 different combinations but localhost never seems to be oopif'd on its own, so we need at least one publicly hosted page that then also iframes a google-y origin that will guarantee 2 separate processes beyond our localhost one
lighthouse-core/gather/driver.js
Outdated
// Events from subtargets will be stringified and sent back on `Target.receivedMessageFromTarget`. | ||
// We want to receive information about network requests from iframes, so enable the Network domain. | ||
this.sendMessageToTarget(sessionIdPath, 'Network.enable'); | ||
this.sendMessageToTarget(sessionIdPath, 'Runtime.runIfWaitingForDebugger'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was too fast for ya already done! :) but yeah i'll add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just the lint error left
LGTM!
DZL is done! Go check it out http://lh-dzl-7608.surge.sh |
For future sleuthing (blame sends you to this PR): I asked Patrick "Why didn't we use flatten?" Answer: the extension protocol API only allows for "send message to target interface". see #7566 (comment) |
Summary
OK, OOPIF fixes attempt 479 :)
The good news: this is now 100% contained in driver.js and should work in all our environments 🎉
The bad news: it's kinda ugly to look at and reason about (we have to do nested Target.sendMessageToTarget calls and unpack nested receiveMessageFromTarget messages)
Related Issues/PRs
#7517 #7566 also #6922 #6337 #6078