Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM.SubscribeToChildNodeInsertedEvent not working #6

Open
SmolinsCo opened this issue Nov 24, 2018 · 0 comments
Open

DOM.SubscribeToChildNodeInsertedEvent not working #6

SmolinsCo opened this issue Nov 24, 2018 · 0 comments

Comments

@SmolinsCo
Copy link

SmolinsCo commented Nov 24, 2018

I using following code:

using System;

using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

using BaristaLabs.ChromeDevTools.Runtime;
using Page = BaristaLabs.ChromeDevTools.Runtime.Page;

namespace BaristaChromeDevToolsTest
{
    class Program
    {
        //Launch Chrome With
        //"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9223

        static async Task Main(string[] args)
        {
            var sessions = await GetSessions("http://localhost:9223/");

            using (var session = new ChromeSession(sessions.First(s => s.Type == "page").WebSocketDebuggerUrl))
            {
                await session.Page.Enable();

                await session.DOM.Enable();

                var loaded = new SemaphoreSlim(0, 1);

                var inserted = new SemaphoreSlim(0, 1);

                session.Page.SubscribeToLoadEventFiredEvent((e) =>
                {
                    loaded.Release();
                });

                var navigateResult = await session.Page.Navigate(new Page.NavigateCommand
                {
                    Url = "http://www.amazon.com"
                });

                // await loaded.WaitAsync();

                session.DOM.SubscribeToChildNodeInsertedEvent((e) => {
                    inserted.Release();
                });

                await inserted.WaitAsync();

                Console.WriteLine("inserted");
            }

            Console.ReadKey();
        }

        public static async Task<ICollection<ChromeSessionInfo>> GetSessions(string chromeUrl)
        {
            using (var webClient = new HttpClient())
            {
                webClient.BaseAddress = new Uri(chromeUrl);
                var remoteSessions = await webClient.GetStringAsync("/json");
                return JsonConvert.DeserializeObject<ICollection<ChromeSessionInfo>>(remoteSessions);
            }
        }
    }
}

Next I opening devtools in this Chrome, evaluating code like such:

var el = document.createElement('div');
document.body.appendChild(el);

...and still no "inserted" in console.
But if I open devtools protocol monitor, I will see DOM.childNodeInserted was called.
Also:
https://chromedevtools.github.io/devtools-protocol/tot/DOM#event-childNodeInserted

DOM.childNodeInserted
Mirrors DOMNodeInserted event.

If I directly subscribe DOMNodeInserted - it fires.

Propose you to write more unit tests.

@SmolinsCo SmolinsCo changed the title DOM.SubscribeToChildNodeRemovedEvent not working DOM.SubscribeToChildNodeInsertedEvent not working Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant