Skip to content

DOM.SubscribeToChildNodeInsertedEvent not working #6

@SmolinsCo

Description

@SmolinsCo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions