diff --git a/dotnet/src/webdriver/DevTools/Target.cs b/dotnet/src/webdriver/DevTools/Target.cs index 3bace60cb97b0..ee8642c93f91f 100644 --- a/dotnet/src/webdriver/DevTools/Target.cs +++ b/dotnet/src/webdriver/DevTools/Target.cs @@ -32,6 +32,11 @@ public abstract class Target /// public event EventHandler TargetDetached; + /// + /// Occurs when a target is attached. + /// + public event EventHandler TargetAttached; + /// /// Asynchronously gets the targets available for this session. /// @@ -79,5 +84,17 @@ protected virtual void OnTargetDetached(TargetDetachedEventArgs e) this.TargetDetached(this, e); } } + + /// + /// Raises the TargetAttached event. + /// + /// + protected virtual void OnTargetAttached(TargetAttachedEventArgs e) + { + if (this.TargetAttached != null) + { + this.TargetAttached(this, e); + } + } } } diff --git a/dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs b/dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs new file mode 100644 index 0000000000000..195bb9b040497 --- /dev/null +++ b/dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs @@ -0,0 +1,41 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; + +namespace OpenQA.Selenium.DevTools +{ + /// + /// Event arguments present when the TargetAttached event is raised. + /// + public class TargetAttachedEventArgs : EventArgs + { + /// + /// Gets the ID of the session of the target attached. + /// + public string SessionId { get; internal set; } + /// + /// Gets the target which is attached. + /// + public TargetInfo TargetInfo { get; internal set; } + /// + /// Gets if the target is waiting on the debugger. Target continues after invoking Runtime.runIfWaitingForDebugger. + /// + public bool WaitingForDebugger { get; internal set; } + } +} diff --git a/dotnet/src/webdriver/DevTools/v117/V117Target.cs b/dotnet/src/webdriver/DevTools/v117/V117Target.cs index 2c39c07693937..37b3a801ff51f 100644 --- a/dotnet/src/webdriver/DevTools/v117/V117Target.cs +++ b/dotnet/src/webdriver/DevTools/v117/V117Target.cs @@ -40,6 +40,7 @@ public V117Target(TargetAdapter adapter) { this.adapter = adapter; adapter.DetachedFromTarget += OnDetachedFromTarget; + adapter.AttachedToTarget += OnAttachedToTarget; } /// @@ -120,5 +121,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); } + + private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + { + this.OnTargetAttached(new TargetAttachedEventArgs() + { + SessionId = e.SessionId, + TargetInfo = e.TargetInfo == null ? null : new TargetInfo + { + BrowserContextId = e.TargetInfo.BrowserContextId, + IsAttached = e.TargetInfo.Attached, + OpenerId = e.TargetInfo.OpenerId, + TargetId = e.TargetInfo.TargetId, + Title = e.TargetInfo.Title, + Type = e.TargetInfo.Type, + Url = e.TargetInfo.Url + }, + WaitingForDebugger = e.WaitingForDebugger + }); + } } } diff --git a/dotnet/src/webdriver/DevTools/v118/V118Target.cs b/dotnet/src/webdriver/DevTools/v118/V118Target.cs index a46f195f8af69..1917c398c02d3 100644 --- a/dotnet/src/webdriver/DevTools/v118/V118Target.cs +++ b/dotnet/src/webdriver/DevTools/v118/V118Target.cs @@ -40,6 +40,7 @@ public V118Target(TargetAdapter adapter) { this.adapter = adapter; adapter.DetachedFromTarget += OnDetachedFromTarget; + adapter.AttachedToTarget += OnAttachedToTarget; } /// @@ -120,5 +121,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); } + + private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + { + this.OnTargetAttached(new TargetAttachedEventArgs() + { + SessionId = e.SessionId, + TargetInfo = e.TargetInfo == null ? null : new TargetInfo + { + BrowserContextId = e.TargetInfo.BrowserContextId, + IsAttached = e.TargetInfo.Attached, + OpenerId = e.TargetInfo.OpenerId, + TargetId = e.TargetInfo.TargetId, + Title = e.TargetInfo.Title, + Type = e.TargetInfo.Type, + Url = e.TargetInfo.Url + }, + WaitingForDebugger = e.WaitingForDebugger + }); + } } } diff --git a/dotnet/src/webdriver/DevTools/v119/V119Target.cs b/dotnet/src/webdriver/DevTools/v119/V119Target.cs index 50f7677c12a69..a376e2b01d533 100644 --- a/dotnet/src/webdriver/DevTools/v119/V119Target.cs +++ b/dotnet/src/webdriver/DevTools/v119/V119Target.cs @@ -40,6 +40,7 @@ public V119Target(TargetAdapter adapter) { this.adapter = adapter; adapter.DetachedFromTarget += OnDetachedFromTarget; + adapter.AttachedToTarget += OnAttachedToTarget; } /// @@ -120,5 +121,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); } + + private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + { + this.OnTargetAttached(new TargetAttachedEventArgs() + { + SessionId = e.SessionId, + TargetInfo = e.TargetInfo == null ? null : new TargetInfo + { + BrowserContextId = e.TargetInfo.BrowserContextId, + IsAttached = e.TargetInfo.Attached, + OpenerId = e.TargetInfo.OpenerId, + TargetId = e.TargetInfo.TargetId, + Title = e.TargetInfo.Title, + Type = e.TargetInfo.Type, + Url = e.TargetInfo.Url + }, + WaitingForDebugger = e.WaitingForDebugger + }); + } } } diff --git a/dotnet/src/webdriver/DevTools/v85/V85Target.cs b/dotnet/src/webdriver/DevTools/v85/V85Target.cs index 02a3b114bcd1d..6d73a06054e9a 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85Target.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85Target.cs @@ -40,6 +40,7 @@ public V85Target(TargetAdapter adapter) { this.adapter = adapter; adapter.DetachedFromTarget += OnDetachedFromTarget; + adapter.AttachedToTarget += OnAttachedToTarget; } /// @@ -115,5 +116,24 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); } + + private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) + { + this.OnTargetAttached(new TargetAttachedEventArgs() + { + SessionId = e.SessionId, + TargetInfo = e.TargetInfo == null ? null : new TargetInfo + { + BrowserContextId = e.TargetInfo.BrowserContextId, + IsAttached = e.TargetInfo.Attached, + OpenerId = e.TargetInfo.OpenerId, + TargetId = e.TargetInfo.TargetId, + Title = e.TargetInfo.Title, + Type = e.TargetInfo.Type, + Url = e.TargetInfo.Url + }, + WaitingForDebugger = e.WaitingForDebugger + }); + } } }