コード例 #1
0
        private async Task <Page> CreatePageAsync()
        {
            var client = await _sessionFactory().ConfigureAwait(false);

            var chromiumPage = new ChromiumPage(client, _browser, BrowserContext);

            _page = chromiumPage.Page;
            chromiumPage.Target = this;

            client.Disconnected += (sender, e) => _page.DidDisconnected();

            client.MessageReceived += (sender, e) =>
            {
                if (e is TargetAttachedToTargetChromiumEvent response)
                {
                    if (response.TargetInfo.GetTargetType() != TargetType.ServiceWorker)
                    {
                        _ = client.SendAsync(new TargetDetachFromTargetRequest {
                            SessionId = response.SessionId
                        });
                    }
                }
            };

            await chromiumPage.InitializeAsync().ConfigureAwait(false);

            await client.SendAsync(new TargetSetAutoAttachRequest
            {
                AutoAttach             = true,
                WaitForDebuggerOnStart = false,
                Flatten = true,
            }).ConfigureAwait(false);

            return(_page);
        }
コード例 #2
0
 internal Task ClosePageAsync(ChromiumPage page)
 => _session.SendAsync(new TargetCloseTargetRequest {
     TargetId = page.Target.TargetId
 });
コード例 #3
0
 public ChromiumNetworkManager(ChromiumSession client, ChromiumPage chromiumPage)
 {
     _client       = client;
     _chromiumPage = chromiumPage;
 }