Skip to content

Commit

Permalink
Separate target init from construction
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Sep 20, 2023
1 parent 54ac49c commit 94dc1b7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/PuppeteerSharp/ChromeTargetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private void OnTargetCreated(TargetCreatedResponse e)
}

var target = _targetFactoryFunc(e.TargetInfo, null);
target.Initialize();
_attachedTargetsByTargetId.AddItem(e.TargetInfo.TargetId, target);
}
}
Expand Down Expand Up @@ -288,6 +289,7 @@ await parent.SendAsync(
}

var workerTarget = _targetFactoryFunc(targetInfo, null);
workerTarget.Initialize();
_attachedTargetsByTargetId.AddItem(targetInfo.TargetId, workerTarget);
TargetAvailable?.Invoke(this, new TargetChangedArgs { Target = workerTarget });
return;
Expand Down Expand Up @@ -316,6 +318,8 @@ await parent.SendAsync(
}
else
{
target.Initialize();

_attachedTargetsByTargetId.AddItem(targetInfo.TargetId, target);
_attachedTargetsBySessionId.TryAdd(session.Id, target);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/PuppeteerSharp/FirefoxTargetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private void OnTargetCreated(TargetCreatedResponse e)
if (e.TargetInfo.Type == TargetType.Browser && e.TargetInfo.Attached)
{
var browserTarget = _targetFactoryFunc(e.TargetInfo, null);
browserTarget.Initialize();
_availableTargetsByTargetId.AddItem(e.TargetInfo.TargetId, browserTarget);
FinishInitializationIfReady(e.TargetInfo.TargetId);
}
Expand All @@ -129,6 +130,7 @@ private void OnTargetCreated(TargetCreatedResponse e)
return;
}

target.Initialize();
_availableTargetsByTargetId.AddItem(e.TargetInfo.TargetId, target);
TargetAvailable?.Invoke(
this,
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal void TargetInfoChanged(TargetInfo targetInfo)
/// <summary>
/// Initializes the target.
/// </summary>
protected virtual void Initialize()
internal virtual void Initialize()
{
IsInitialized = true;
InitializedTaskWrapper.TrySetResult(InitializationStatus.Success);
Expand Down

0 comments on commit 94dc1b7

Please sign in to comment.