From 64f9243a0abe4563f8b195fa63a1a5d243fcc72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 20 Sep 2023 14:55:18 -0300 Subject: [PATCH] Separate target init from construction --- lib/PuppeteerSharp/ChromeTargetManager.cs | 4 ++++ lib/PuppeteerSharp/FirefoxTargetManager.cs | 2 ++ lib/PuppeteerSharp/PageTarget.cs | 2 +- lib/PuppeteerSharp/Target.cs | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/PuppeteerSharp/ChromeTargetManager.cs b/lib/PuppeteerSharp/ChromeTargetManager.cs index 3446df4d2..b63312fbd 100644 --- a/lib/PuppeteerSharp/ChromeTargetManager.cs +++ b/lib/PuppeteerSharp/ChromeTargetManager.cs @@ -199,6 +199,7 @@ private void OnTargetCreated(TargetCreatedResponse e) } var target = _targetFactoryFunc(e.TargetInfo, null); + target.Initialize(); _attachedTargetsByTargetId.AddItem(e.TargetInfo.TargetId, target); } } @@ -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; @@ -316,6 +318,8 @@ await parent.SendAsync( } else { + target.Initialize(); + _attachedTargetsByTargetId.AddItem(targetInfo.TargetId, target); _attachedTargetsBySessionId.TryAdd(session.Id, target); } diff --git a/lib/PuppeteerSharp/FirefoxTargetManager.cs b/lib/PuppeteerSharp/FirefoxTargetManager.cs index 12aa7835e..ef5f24998 100644 --- a/lib/PuppeteerSharp/FirefoxTargetManager.cs +++ b/lib/PuppeteerSharp/FirefoxTargetManager.cs @@ -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); } @@ -129,6 +130,7 @@ private void OnTargetCreated(TargetCreatedResponse e) return; } + target.Initialize(); _availableTargetsByTargetId.AddItem(e.TargetInfo.TargetId, target); TargetAvailable?.Invoke( this, diff --git a/lib/PuppeteerSharp/PageTarget.cs b/lib/PuppeteerSharp/PageTarget.cs index aab5301f5..bb920aaf2 100644 --- a/lib/PuppeteerSharp/PageTarget.cs +++ b/lib/PuppeteerSharp/PageTarget.cs @@ -39,7 +39,7 @@ public override async Task PageAsync() return await PageTask.ConfigureAwait(false); } - protected override void Initialize() + internal override void Initialize() { _ = InitializedTaskWrapper.Task.ContinueWith( async initializedTask => diff --git a/lib/PuppeteerSharp/Target.cs b/lib/PuppeteerSharp/Target.cs index 44e886083..826dfdf11 100644 --- a/lib/PuppeteerSharp/Target.cs +++ b/lib/PuppeteerSharp/Target.cs @@ -85,7 +85,7 @@ internal void TargetInfoChanged(TargetInfo targetInfo) /// /// Initializes the target. /// - protected virtual void Initialize() + internal virtual void Initialize() { IsInitialized = true; InitializedTaskWrapper.TrySetResult(InitializationStatus.Success);