-
Notifications
You must be signed in to change notification settings - Fork 32
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
create
and navigate.browsingContext
#55
Conversation
f7700df
to
89609d2
Compare
browsingContext.navigate
browsingContext
creation and navigation
browsingContext
creation and navigationcreate
and navigate.browsingContext
ba79ff1
to
4c0cf3d
Compare
896600f
to
1c08cbe
Compare
1be66dd
to
c1c3e1c
Compare
1c08cbe
to
536afd4
Compare
c1c3e1c
to
74244e3
Compare
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've reviewed about half way through, sending the comments I have before I head into a meeting.
EVALUATOR_SCRIPT | ||
); | ||
|
||
// Actual `Context.create` logic involves several CDP calls, so mock it to avoid all the simulations. |
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 a helpful comment, thanks!
Co-authored-by: Philip Jägenstedt <philip@foolip.org>
browsingContextProcessor = new BrowsingContextProcessor( | ||
cdpConnection, | ||
'SELF_TARGET_ID', | ||
sinon.fake as unknown as (t: Context) => Promise<void>, |
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 you wrap the sinon.fake as unknown as (t: Context) => Promise<void>
code into a typedFake
function similar to typedSpy
?
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, shouldn't this call fake
(e.g. fake()
)?
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.
Fixed
|
||
const existingContext = await this._tryGetContext(targetId); | ||
if (existingContext) { | ||
resolve(existingContext.toBidi()); |
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 think awaiting here might introduce a potential race condition. Once Target.createTarget returns, we need to register the onAttachToTarget handler synchronously, or there's a chance the event will come and we'll miss it.
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.
Agree. Added synchronous check, if the context is already known, in which case attachedToTarget
is not needed.
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'm not sure I understand how the latest change will solve the race condition. I see that line 172 is checking for a known contextId. But, we're creating a new blank CDP target on line 165, so won't we always have a new unknown contextId?
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.
If the event came at the moment of line 172, it means it was handled by _handleAttachedToTargetEvent
in line 54. If not, the code will go synchronously till line 195, where event handler is attached. Having the second handler in line 195 is needed just to resolve the command promise.
It looks confusing. Another option is to keep a single event handler in this class BrowsingContextProcessor
in line 54. But in this case, we have to notify the process_PROTO_browsingContext_create
command when the context is actually attached and initialized.
The first (current) approach allows to use built-in events queue like browserCdpClient.Target.on
. The second approach requires introducing our internal event queue and subscription mechanism.
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.
Thank you, that makes more sense. I think this is safe then. Even though await this._tryGetContext(targetId)
will yield to the runtime, any attachedToTarget
event should be handled by _handleAttachedToTargetEvent
and the context will be put in the map before _tryGetContext
actually executes.
@@ -80,6 +87,23 @@ export class Context { | |||
}; | |||
} | |||
|
|||
public async navigate( | |||
url: string, | |||
wait: BrowsingContext.ReadinessState = 'none' |
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.
A default parameter makes sense at the API level, but for clarity, I'd prefer to avoid them in internal/implementation classes.
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.
done
|
||
const existingContext = await this._tryGetContext(targetId); | ||
if (existingContext) { | ||
resolve(existingContext.toBidi()); |
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'm not sure I understand how the latest change will solve the race condition. I see that line 172 is checking for a known contextId. But, we're creating a new blank CDP target on line 165, so won't we always have a new unknown contextId?
I replied @bwalderman in the thread #55 (comment) |
|
||
const existingContext = await this._tryGetContext(targetId); | ||
if (existingContext) { | ||
resolve(existingContext.toBidi()); |
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.
Thank you, that makes more sense. I think this is safe then. Even though await this._tryGetContext(targetId)
will yield to the runtime, any attachedToTarget
event should be handled by _handleAttachedToTargetEvent
and the context will be put in the map before _tryGetContext
actually executes.
browsingContext.navigate
command.browsingContext.create
->params.type
.browsingContext.create
.EVALUATOR_SCRIPT
a property to allow unit testing.BrowsingContextProcessor
is responsible for handling events for testability.