diff --git a/src/Playwright/Core/APIRequest.cs b/src/Playwright/Core/APIRequest.cs index 342f067df9..1e676c3e5b 100644 --- a/src/Playwright/Core/APIRequest.cs +++ b/src/Playwright/Core/APIRequest.cs @@ -27,7 +27,6 @@ using System.Text.Json; using System.Threading.Tasks; using Microsoft.Playwright.Helpers; -using Microsoft.Playwright.Transport.Channels; namespace Microsoft.Playwright.Core; @@ -67,9 +66,9 @@ async Task IAPIRequest.NewContextAsync(APIRequestNewContextO args.Add("storageState", JsonSerializer.Deserialize(storageState, Helpers.JsonExtensions.DefaultJsonSerializerOptions)); } - var context = (await _playwright.SendMessageToServerAsync( + var context = await _playwright.SendMessageToServerAsync( "newRequest", - args).ConfigureAwait(false)).Object; + args).ConfigureAwait(false); context._request = this; return context; } diff --git a/src/Playwright/Core/APIRequestContext.cs b/src/Playwright/Core/APIRequestContext.cs index 90feac8490..e10f64b03f 100644 --- a/src/Playwright/Core/APIRequestContext.cs +++ b/src/Playwright/Core/APIRequestContext.cs @@ -31,28 +31,21 @@ using System.Threading.Tasks; using Microsoft.Playwright.Helpers; using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; -internal class APIRequestContext : ChannelOwnerBase, IChannelOwner, IAPIRequestContext +internal class APIRequestContext : ChannelOwnerBase, IAPIRequestContext { - internal readonly APIRequestContextChannel _channel; internal readonly Tracing _tracing; internal APIRequest _request; - public APIRequestContext(IChannelOwner parent, string guid, APIRequestContextInitializer initializer) : base(parent, guid) + public APIRequestContext(ChannelOwnerBase parent, string guid, APIRequestContextInitializer initializer) : base(parent, guid) { - _channel = new(guid, parent.Connection, this); _tracing = initializer.Tracing; } - ChannelBase IChannelOwner.Channel => _channel; - - IChannel IChannelOwner.Channel => _channel; - [MethodImpl(MethodImplOptions.NoInlining)] public ValueTask DisposeAsync() => new(SendMessageToServerAsync("dispose")); diff --git a/src/Playwright/Core/Accessibility.cs b/src/Playwright/Core/Accessibility.cs index 474cc36280..9c2d6c1938 100644 --- a/src/Playwright/Core/Accessibility.cs +++ b/src/Playwright/Core/Accessibility.cs @@ -25,26 +25,25 @@ using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; -using Microsoft.Playwright.Transport.Channels; namespace Microsoft.Playwright.Core; internal class Accessibility : IAccessibility { - private readonly PageChannel _channel; + private readonly Page _page; - public Accessibility(PageChannel channel) + public Accessibility(Page page) { - _channel = channel; + _page = page; } public async Task SnapshotAsync(AccessibilitySnapshotOptions options = default) { options ??= new(); - if ((await _channel.Object.SendMessageToServerAsync("accessibilitySnapshot", new Dictionary + if ((await _page.SendMessageToServerAsync("accessibilitySnapshot", new Dictionary { ["interestingOnly"] = options?.InterestingOnly, - ["root"] = (options.Root as ElementHandle)?.ElementChannel, + ["root"] = options.Root, }).ConfigureAwait(false)).Value.TryGetProperty("rootAXNode", out var jsonElement)) { return jsonElement; diff --git a/src/Playwright/Core/AndroidDevice.cs b/src/Playwright/Core/AndroidDevice.cs index 9baf6fb9ed..05ef136231 100644 --- a/src/Playwright/Core/AndroidDevice.cs +++ b/src/Playwright/Core/AndroidDevice.cs @@ -23,14 +23,13 @@ */ using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; internal class AndroidDevice : ChannelOwnerBase { - internal AndroidDevice(IChannelOwner parent, string guid, BrowserInitializer initializer) : base(parent, guid) + internal AndroidDevice(ChannelOwnerBase parent, string guid, BrowserInitializer initializer) : base(parent, guid) { } } diff --git a/src/Playwright/Core/Artifact.cs b/src/Playwright/Core/Artifact.cs index 269d75b426..101ef351b2 100644 --- a/src/Playwright/Core/Artifact.cs +++ b/src/Playwright/Core/Artifact.cs @@ -29,27 +29,17 @@ using System.Threading.Tasks; using Microsoft.Playwright.Helpers; using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; -internal class Artifact : ChannelOwnerBase, IChannelOwner +internal class Artifact : ChannelOwnerBase { - private readonly ArtifactChannel _channel; - - internal Artifact(IChannelOwner parent, string guid, ArtifactInitializer initializer) : base(parent, guid) + internal Artifact(ChannelOwnerBase parent, string guid, ArtifactInitializer initializer) : base(parent, guid) { - _channel = new(guid, parent.Connection, this); AbsolutePath = initializer.AbsolutePath; } - Connection IChannelOwner.Connection => _connection; - - ChannelBase IChannelOwner.Channel => _channel; - - IChannel IChannelOwner.Channel => _channel; - internal string AbsolutePath { get; } [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/src/Playwright/Core/BindingCall.cs b/src/Playwright/Core/BindingCall.cs index 7da41e4000..d102fbc081 100644 --- a/src/Playwright/Core/BindingCall.cs +++ b/src/Playwright/Core/BindingCall.cs @@ -29,30 +29,23 @@ using System.Threading.Tasks; using Microsoft.Playwright.Helpers; using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; -internal class BindingCall : ChannelOwnerBase, IChannelOwner +internal class BindingCall : ChannelOwnerBase { private static readonly Type VoidTaskResultType = Type.GetType("System.Threading.Tasks.VoidTaskResult"); - private readonly BindingCallChannel _channel; private readonly BindingCallInitializer _initializer; - public BindingCall(IChannelOwner parent, string guid, BindingCallInitializer initializer) : base(parent, guid) + public BindingCall(ChannelOwnerBase parent, string guid, BindingCallInitializer initializer) : base(parent, guid) { - _channel = new(guid, parent.Connection, this); _initializer = initializer; } public string Name => _initializer.Name; - ChannelBase IChannelOwner.Channel => _channel; - - IChannel IChannelOwner.Channel => _channel; - internal async Task CallAsync(Delegate binding) { try diff --git a/src/Playwright/Core/Browser.cs b/src/Playwright/Core/Browser.cs index e05885af0b..7d6ebce455 100644 --- a/src/Playwright/Core/Browser.cs +++ b/src/Playwright/Core/Browser.cs @@ -32,12 +32,11 @@ using System.Threading.Tasks; using Microsoft.Playwright.Helpers; using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; -internal class Browser : ChannelOwnerBase, IChannelOwner, IBrowser +internal class Browser : ChannelOwnerBase, IBrowser { private readonly BrowserInitializer _initializer; private readonly TaskCompletionSource _closedTcs = new(); @@ -45,19 +44,14 @@ internal class Browser : ChannelOwnerBase, IChannelOwner, IBrowser internal BrowserType _browserType; internal string _closeReason; - internal Browser(IChannelOwner parent, string guid, BrowserInitializer initializer) : base(parent, guid) + internal Browser(ChannelOwnerBase parent, string guid, BrowserInitializer initializer) : base(parent, guid) { - Channel = new(guid, parent.Connection, this); IsConnected = true; _initializer = initializer; } public event EventHandler Disconnected; - ChannelBase IChannelOwner.Channel => Channel; - - IChannel IChannelOwner.Channel => Channel; - public IReadOnlyList Contexts => _contexts.ToArray(); public bool IsConnected { get; private set; } @@ -66,8 +60,6 @@ internal Browser(IChannelOwner parent, string guid, BrowserInitializer initializ public string Version => _initializer.Version; - internal BrowserChannel Channel { get; } - public IBrowserType BrowserType => _browserType; internal override void OnMessage(string method, JsonElement? serverParams) @@ -88,11 +80,11 @@ public async Task CloseAsync(BrowserCloseOptions options = default) { if (ShouldCloseConnectionOnClose) { - Channel.Connection.DoClose(); + _connection.DoClose(); } else { - await SendMessageToServerAsync("close", new Dictionary + await SendMessageToServerAsync("close", new Dictionary { ["reason"] = options?.Reason, }).ConfigureAwait(false); @@ -175,7 +167,7 @@ public async Task NewContextAsync(BrowserNewContextOptions opti args.Add("screen", options.ScreenSize); } - var context = (await SendMessageToServerAsync("newContext", args).ConfigureAwait(false)).Object; + var context = await SendMessageToServerAsync("newContext", args).ConfigureAwait(false); _browserType.DidCreateContext(context, options, null); return context; @@ -274,8 +266,8 @@ internal void DidClose() [MethodImpl(MethodImplOptions.NoInlining)] public async Task NewBrowserCDPSessionAsync() - => (await SendMessageToServerAsync( - "newBrowserCDPSession").ConfigureAwait(false)).Object; + => await SendMessageToServerAsync( + "newBrowserCDPSession").ConfigureAwait(false); internal static Dictionary PrepareHarOptions( HarContentPolicy? recordHarContent, diff --git a/src/Playwright/Core/BrowserContext.cs b/src/Playwright/Core/BrowserContext.cs index 3202711518..5794d17a4c 100644 --- a/src/Playwright/Core/BrowserContext.cs +++ b/src/Playwright/Core/BrowserContext.cs @@ -38,7 +38,7 @@ namespace Microsoft.Playwright.Core; -internal class BrowserContext : ChannelOwnerBase, IChannelOwner, IBrowserContext +internal class BrowserContext : ChannelOwnerBase, IBrowserContext { private readonly TaskCompletionSource _closeTcs = new(); private readonly Dictionary _bindings = new(); @@ -55,11 +55,10 @@ internal class BrowserContext : ChannelOwnerBase, IChannelOwner, internal TimeoutSettings _timeoutSettings = new(); - internal BrowserContext(IChannelOwner parent, string guid, BrowserContextInitializer initializer) : base(parent, guid) + internal BrowserContext(ChannelOwnerBase parent, string guid, BrowserContextInitializer initializer) : base(parent, guid) { _browser = parent as Browser; _browser?._contexts.Add(this); - Channel = new(guid, parent.Connection, this); _tracing = initializer.Tracing; _request = initializer.RequestContext; @@ -128,16 +127,10 @@ public ITracing Tracing set => throw new NotSupportedException(); } - ChannelBase IChannelOwner.Channel => Channel; - - IChannel IChannelOwner.Channel => Channel; - public IBrowser Browser => _browser; public IReadOnlyList Pages => _pages; - internal BrowserContextChannel Channel { get; } - internal Page OwnerPage { get; set; } internal bool IsChromium => _initializer.IsChromium; @@ -157,10 +150,10 @@ internal override void OnMessage(string method, JsonElement? serverParams) break; case "bindingCall": Channel_BindingCall( - serverParams?.GetProperty("binding").ToObject(_connection.DefaultJsonSerializerOptions).Object); + serverParams?.GetProperty("binding").ToObject(_connection.DefaultJsonSerializerOptions)); break; case "dialog": - OnDialog(serverParams?.GetProperty("dialog").ToObject(_connection.DefaultJsonSerializerOptions).Object); + OnDialog(serverParams?.GetProperty("dialog").ToObject(_connection.DefaultJsonSerializerOptions)); break; case "console": var consoleMessage = new ConsoleMessage(serverParams?.ToObject(_connection.DefaultJsonSerializerOptions)); @@ -171,19 +164,18 @@ internal override void OnMessage(string method, JsonElement? serverParams) } break; case "route": - var route = serverParams?.GetProperty("route").ToObject(_connection.DefaultJsonSerializerOptions).Object; + var route = serverParams?.GetProperty("route").ToObject(_connection.DefaultJsonSerializerOptions); Channel_Route(this, route); break; case "page": Channel_OnPage( this, - serverParams?.GetProperty("page").ToObject(_connection.DefaultJsonSerializerOptions)); + serverParams?.GetProperty("page").ToObject(_connection.DefaultJsonSerializerOptions)); break; case "pageError": { var error = serverParams?.GetProperty("error").ToObject(_connection.DefaultJsonSerializerOptions); - var pageChannel = serverParams?.GetProperty("page").ToObject(_connection.DefaultJsonSerializerOptions); - var pageObject = pageChannel?.Object; + var pageObject = serverParams?.GetProperty("page").ToObject(_connection.DefaultJsonSerializerOptions); var parsedError = string.IsNullOrEmpty(error.Error.Stack) ? $"{error.Error.Name}: {error.Error.Message}" : error.Error.Stack; WebError?.Invoke(this, new WebError(pageObject, parsedError)); pageObject?.FirePageError(parsedError); @@ -191,7 +183,7 @@ internal override void OnMessage(string method, JsonElement? serverParams) } case "serviceWorker": { - var serviceWorker = serverParams?.GetProperty("worker").ToObject(_connection.DefaultJsonSerializerOptions).Object; + var serviceWorker = serverParams?.GetProperty("worker").ToObject(_connection.DefaultJsonSerializerOptions); ((Worker)serviceWorker).Context = this; _serviceWorkers.Add(serviceWorker); ServiceWorker?.Invoke(this, serviceWorker); @@ -260,7 +252,7 @@ internal void OnDialog(IDialog dialog) } [MethodImpl(MethodImplOptions.NoInlining)] - public Task AddCookiesAsync(IEnumerable cookies) => SendMessageToServerAsync( + public Task AddCookiesAsync(IEnumerable cookies) => SendMessageToServerAsync( "addCookies", new Dictionary { @@ -275,7 +267,7 @@ public Task AddInitScriptAsync(string script = null, string scriptPath = null) script = ScriptsHelper.EvaluationScript(script, scriptPath); } - return SendMessageToServerAsync( + return SendMessageToServerAsync( "addInitScript", new Dictionary { @@ -315,7 +307,7 @@ await WrapApiCallAsync( if (isCompressed && !needCompressed) { await artifact.SaveAsAsync(harRecorder.Value.Path + ".tmp").ConfigureAwait(false); - await Channel.Connection.LocalUtils.HarUnzipAsync(harRecorder.Value.Path + ".tmp", harRecorder.Value.Path).ConfigureAwait(false); + await _connection.LocalUtils.HarUnzipAsync(harRecorder.Value.Path + ".tmp", harRecorder.Value.Path).ConfigureAwait(false); } else { @@ -416,7 +408,7 @@ public Task ExposeFunctionAsync(string name, Func permissions, BrowserContextGrantPermissionsOptions options = default) - => SendMessageToServerAsync("grantPermissions", new Dictionary + => SendMessageToServerAsync("grantPermissions", new Dictionary { ["permissions"] = permissions?.ToArray(), ["origin"] = options?.Origin, @@ -424,21 +416,21 @@ public Task GrantPermissionsAsync(IEnumerable permissions, BrowserContex [MethodImpl(MethodImplOptions.NoInlining)] public async Task NewCDPSessionAsync(IPage page) - => (await SendMessageToServerAsync( + => await SendMessageToServerAsync( "newCDPSession", new Dictionary { ["page"] = new { guid = (page as Page).Guid }, - }).ConfigureAwait(false)).Object; + }).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public async Task NewCDPSessionAsync(IFrame frame) - => (await SendMessageToServerAsync( + => await SendMessageToServerAsync( "newCDPSession", new Dictionary { ["frame"] = new { guid = (frame as Frame).Guid }, - }).ConfigureAwait(false)).Object; + }).ConfigureAwait(false); [MethodImpl(MethodImplOptions.NoInlining)] public async Task NewPageAsync() @@ -448,7 +440,7 @@ public async Task NewPageAsync() throw new PlaywrightException("Please use Browser.NewContextAsync()"); } - return (await SendMessageToServerAsync("newPage").ConfigureAwait(false)).Object; + return await SendMessageToServerAsync("newPage").ConfigureAwait(false); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -485,7 +477,7 @@ public Task SetExtraHTTPHeadersAsync(IEnumerable> h }); [MethodImpl(MethodImplOptions.NoInlining)] - public Task SetGeolocationAsync(Geolocation geolocation) => SendMessageToServerAsync( + public Task SetGeolocationAsync(Geolocation geolocation) => SendMessageToServerAsync( "setGeolocation", new Dictionary { @@ -493,7 +485,7 @@ public Task SetGeolocationAsync(Geolocation geolocation) => SendMessageToServerA }); [MethodImpl(MethodImplOptions.NoInlining)] - public Task SetOfflineAsync(bool offline) => SendMessageToServerAsync( + public Task SetOfflineAsync(bool offline) => SendMessageToServerAsync( "setOffline", new Dictionary { @@ -596,7 +588,7 @@ internal void SetDefaultNavigationTimeoutImpl(float? timeout) { _timeoutSettings.SetDefaultNavigationTimeout(timeout); WrapApiCallAsync( - () => SendMessageToServerAsync( + () => SendMessageToServerAsync( "setDefaultNavigationTimeoutNoReply", new Dictionary { @@ -612,7 +604,7 @@ internal void SetDefaultTimeoutImpl(float? timeout) { _timeoutSettings.SetDefaultTimeout(timeout); WrapApiCallAsync( - () => SendMessageToServerAsync( + () => SendMessageToServerAsync( "setDefaultTimeoutNoReply", new Dictionary { @@ -726,9 +718,8 @@ internal void OnClose() _closeTcs.TrySetResult(true); } - private void Channel_OnPage(object sender, PageChannel pageChannel) + private void Channel_OnPage(object sender, Page page) { - var page = pageChannel.Object; page.Context = this; _pages.Add(page); Page?.Invoke(this, page); @@ -766,7 +757,7 @@ private Task ExposeBindingAsync(string name, Delegate callback, bool handle = fa _bindings.Add(name, callback); - return SendMessageToServerAsync( + return SendMessageToServerAsync( "exposeBinding", new Dictionary { @@ -793,7 +784,7 @@ internal async Task RecordIntoHarAsync(string har, Page page, BrowserContextRout var contentPolicy = RouteFromHarUpdateContentPolicyToHarContentPolicy(options?.UpdateContent); var harId = (await SendMessageToServerAsync("harStart", new Dictionary { - { "page", page?.Channel }, + { "page", page }, { "options", Core.Browser.PrepareHarOptions(contentPolicy ?? HarContentPolicy.Attach, options.UpdateMode ?? HarMode.Minimal, har, null, options.Url, options.UrlString, options.UrlRegex) }, }).ConfigureAwait(false)).GetString("harId", false); _harRecorders.Add(harId, new() { Path = har, Content = contentPolicy ?? HarContentPolicy.Attach }); @@ -807,7 +798,7 @@ public async Task RouteFromHARAsync(string har, BrowserContextRouteFromHAROption await RecordIntoHarAsync(har, null, options).ConfigureAwait(false); return; } - var harRouter = await HarRouter.CreateAsync(Channel.Connection.LocalUtils, har, options?.NotFound ?? HarNotFound.Abort, new() + var harRouter = await HarRouter.CreateAsync(_connection.LocalUtils, har, options?.NotFound ?? HarNotFound.Abort, new() { Url = options?.Url, UrlRegex = options?.UrlRegex, diff --git a/src/Playwright/Core/BrowserType.cs b/src/Playwright/Core/BrowserType.cs index c1b92c5b32..f704d53bec 100644 --- a/src/Playwright/Core/BrowserType.cs +++ b/src/Playwright/Core/BrowserType.cs @@ -30,26 +30,19 @@ using System.Threading.Tasks; using Microsoft.Playwright.Helpers; using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; -internal class BrowserType : ChannelOwnerBase, IChannelOwner, IBrowserType +internal class BrowserType : ChannelOwnerBase, IBrowserType { private readonly BrowserTypeInitializer _initializer; - private readonly BrowserTypeChannel _channel; - internal BrowserType(IChannelOwner parent, string guid, BrowserTypeInitializer initializer) : base(parent, guid) + internal BrowserType(ChannelOwnerBase parent, string guid, BrowserTypeInitializer initializer) : base(parent, guid) { _initializer = initializer; - _channel = new(guid, parent.Connection, this); } - ChannelBase IChannelOwner.Channel => _channel; - - IChannel IChannelOwner.Channel => _channel; - internal PlaywrightImpl Playwright { get; set; } public string ExecutablePath => _initializer.ExecutablePath; @@ -60,7 +53,7 @@ internal BrowserType(IChannelOwner parent, string guid, BrowserTypeInitializer i public async Task LaunchAsync(BrowserTypeLaunchOptions options = default) { options ??= new BrowserTypeLaunchOptions(); - Browser browser = (await SendMessageToServerAsync( + Browser browser = await SendMessageToServerAsync( "launch", new Dictionary { @@ -82,7 +75,7 @@ public async Task LaunchAsync(BrowserTypeLaunchOptions options = defau { "chromiumSandbox", options.ChromiumSandbox }, { "slowMo", options.ChromiumSandbox }, { "timeout", options.Timeout }, - }).ConfigureAwait(false)).Object; + }).ConfigureAwait(false); DidLaunchBrowser(browser); return browser; } @@ -158,7 +151,7 @@ public async Task LaunchPersistentContextAsync(string userDataD channelArgs.Add("viewport", options.ViewportSize); } - var context = (await SendMessageToServerAsync("launchPersistentContext", channelArgs).ConfigureAwait(false)).Object; + var context = await SendMessageToServerAsync("launchPersistentContext", channelArgs).ConfigureAwait(false); // TODO: unite with a single browser context options type which is derived from channels DidCreateContext( @@ -188,7 +181,7 @@ public async Task ConnectAsync(string wsEndpoint, BrowserTypeConnectOp { new KeyValuePair("x-playwright-browser", Name), }.ToDictionary(pair => pair.Key, pair => pair.Value); - var localUtils = _channel.Connection.LocalUtils; + var localUtils = _connection.LocalUtils; var pipe = await localUtils.ConnectAsync(wsEndpoint: wsEndpoint, headers: headers, slowMo: options.SlowMo, timeout: options.Timeout, exposeNetwork: options.ExposeNetwork).ConfigureAwait(false); void ClosePipe() @@ -196,7 +189,7 @@ void ClosePipe() pipe.CloseAsync().IgnoreException(); } #pragma warning disable CA2000 // Dispose objects before losing scope - var connection = new Connection(_channel.Connection.LocalUtils); + var connection = new Connection(_connection.LocalUtils); #pragma warning restore CA2000 connection.MarkAsRemote(); connection.Close += (_, _) => ClosePipe(); @@ -243,7 +236,7 @@ void OnPipeClosed() catch (Exception ex) { closeError = ex; - _channel.Connection.TraceMessage("pw:dotnet", $"Dispatching error: {ex.Message}\n{ex.StackTrace}"); + _connection.TraceMessage("pw:dotnet", $"Dispatching error: {ex.Message}\n{ex.StackTrace}"); ClosePipe(); } }; @@ -283,11 +276,11 @@ public async Task ConnectOverCDPAsync(string endpointURL, BrowserTypeC { "slowMo", options.SlowMo }, { "timeout", options.Timeout }, }).ConfigureAwait(false); - Browser browser = result.GetProperty("browser").ToObject(_channel.Connection.DefaultJsonSerializerOptions); + Browser browser = result.GetProperty("browser").ToObject(_connection.DefaultJsonSerializerOptions); DidLaunchBrowser(browser); if (result.TryGetProperty("defaultContext", out JsonElement defaultContextValue)) { - var defaultContext = defaultContextValue.ToObject(_channel.Connection.DefaultJsonSerializerOptions); + var defaultContext = defaultContextValue.ToObject(_connection.DefaultJsonSerializerOptions); DidCreateContext(defaultContext, new(), null); } return browser; diff --git a/src/Playwright/Core/CDPSession.cs b/src/Playwright/Core/CDPSession.cs index 5e73b08883..cf1a23f5d7 100644 --- a/src/Playwright/Core/CDPSession.cs +++ b/src/Playwright/Core/CDPSession.cs @@ -27,26 +27,19 @@ using System.Text.Json; using System.Threading.Tasks; using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; #nullable enable namespace Microsoft.Playwright.Core; -internal class CDPSession : ChannelOwnerBase, ICDPSession, IChannelOwner +internal class CDPSession : ChannelOwnerBase, ICDPSession { - private readonly CDPChannel _channel; private readonly Dictionary _cdpSessionEvents = new(); - public CDPSession(IChannelOwner parent, string guid) : base(parent, guid) + public CDPSession(ChannelOwnerBase parent, string guid) : base(parent, guid) { - _channel = new(guid, parent.Connection, this); } - ChannelBase IChannelOwner.Channel => _channel; - - IChannel IChannelOwner.Channel => _channel; - internal override void OnMessage(string method, JsonElement? serverParams) { switch (method) diff --git a/src/Playwright/Core/Dialog.cs b/src/Playwright/Core/Dialog.cs index 9e15123ae8..90224b8565 100644 --- a/src/Playwright/Core/Dialog.cs +++ b/src/Playwright/Core/Dialog.cs @@ -26,19 +26,16 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; using Microsoft.Playwright.Transport; -using Microsoft.Playwright.Transport.Channels; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; -internal class Dialog : ChannelOwnerBase, IChannelOwner, IDialog +internal class Dialog : ChannelOwnerBase, IDialog { - private readonly DialogChannel _channel; private readonly DialogInitializer _initializer; - public Dialog(IChannelOwner parent, string guid, DialogInitializer initializer) : base(parent, guid) + public Dialog(ChannelOwnerBase parent, string guid, DialogInitializer initializer) : base(parent, guid) { - _channel = new(guid, parent.Connection, this); _initializer = initializer; } @@ -52,12 +49,8 @@ public Dialog(IChannelOwner parent, string guid, DialogInitializer initializer) // Therefore, we must report the dialog without a page to be able to handle it. public IPage Page => _initializer.Page; - ChannelBase IChannelOwner.Channel => _channel; - - IChannel IChannelOwner.Channel => _channel; - [MethodImpl(MethodImplOptions.NoInlining)] - public Task AcceptAsync(string promptText) => SendMessageToServerAsync( + public Task AcceptAsync(string promptText) => SendMessageToServerAsync( "accept", new Dictionary { diff --git a/src/Playwright/Core/ElementHandle.cs b/src/Playwright/Core/ElementHandle.cs index 5a138d2134..4b9dffc1c2 100644 --- a/src/Playwright/Core/ElementHandle.cs +++ b/src/Playwright/Core/ElementHandle.cs @@ -29,26 +29,18 @@ using System.Text.Json; using System.Threading.Tasks; using Microsoft.Playwright.Helpers; -using Microsoft.Playwright.Transport.Channels; +using Microsoft.Playwright.Transport; using Microsoft.Playwright.Transport.Protocol; namespace Microsoft.Playwright.Core; -internal class ElementHandle : JSHandle, IElementHandle, IChannelOwner +internal class ElementHandle : JSHandle, IElementHandle { - private readonly ElementHandleChannel _channel; - internal ElementHandle(IChannelOwner parent, string guid, ElementHandleInitializer initializer) : base(parent, guid, initializer) + internal ElementHandle(ChannelOwnerBase parent, string guid, ElementHandleInitializer initializer) : base(parent, guid, initializer) { - _channel = new(guid, parent.Connection, this); } - ChannelBase IChannelOwner.Channel => _channel; - - IChannel IChannelOwner.Channel => _channel; - - internal IChannel ElementChannel => _channel; - internal override void OnMessage(string method, JsonElement? serverParams) { switch (method) @@ -60,7 +52,7 @@ internal override void OnMessage(string method, JsonElement? serverParams) } public async Task WaitForSelectorAsync(string selector, ElementHandleWaitForSelectorOptions options = default) - => (await SendMessageToServerAsync( + => await SendMessageToServerAsync( "waitForSelector", new Dictionary { @@ -68,7 +60,7 @@ public async Task WaitForSelectorAsync(string selector, ElementH ["timeout"] = options?.Timeout, ["state"] = options?.State, ["strict"] = options?.Strict, - }).ConfigureAwait(false)).Object; + }).ConfigureAwait(false); public Task WaitForElementStateAsync(ElementState state, ElementHandleWaitForElementStateOptions options = default) => SendMessageToServerAsync("waitForElementState", new Dictionary @@ -119,7 +111,7 @@ public async Task ScreenshotAsync(ElementHandleScreenshotOptions options { args["mask"] = options.Mask.Select(locator => new Dictionary { - ["frame"] = ((Locator)locator)._frame._channel, + ["frame"] = ((Locator)locator)._frame, ["selector"] = ((Locator)locator)._selector, }).ToArray(); } @@ -144,7 +136,7 @@ public Task FillAsync(string value, ElementHandleFillOptions options = default) ["noWaitAfter"] = options?.NoWaitAfter, }); - public async Task