App crash when I use CefDomVisitor

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

App crash when I use CefDomVisitor

Postby Artem » Fri May 18, 2018 9:51 am

Hello

I try to use CefDomVisitor for getting DOM elements.

I start from this article https://www.joelverhagen.com/blog/2013/ ... h-cefglue/

I downloaded source code from example and it works fine.
I updated CEF version:
- download CEFGlue from v3325 branch (Assembly version: 65.0.1.0
- download CEF3 binaries 3325.1746.ge81cdf2
- update methods overriding with new version
- up .NET Framework version to 4.5

Now app crashing when CefDomVisitor try to interact with Root field in CefDomDocument.
App show me terminate dialog (two buttons: Close or Debug), I click Close but app doesn't close.

debug.log

[0518/171617.422:INFO:media_foundation_video_encode_accelerator_win.cc(370)] Windows versions earlier than 8 are not supported.
[0518/171618.968:INFO:CONSOLE(341)] "chrome.loadTimes() is deprecated, instead use standardized API: nextHopProtocol in Navigation Timing 2. https://www.chromestatus.com/features/5637885046816768. source: https://apis.google.com/_/scs/abc-stati ... i.loaded_0 (341)
[0518/171618.969:INFO:CONSOLE(341)] "chrome.loadTimes() is deprecated, instead use standardized API: nextHopProtocol in Navigation Timing 2. https://www.chromestatus.com/features/5637885046816768. source: https://apis.google.com/_/scs/abc-stati ... i.loaded_0 (341)
[0518/171618.969:INFO:CONSOLE(341)] "chrome.loadTimes() is deprecated, instead use standardized API: nextHopProtocol in Navigation Timing 2. https://www.chromestatus.com/features/5637885046816768. source: https://apis.google.com/_/scs/abc-stati ... i.loaded_0 (341)
[0518/171618.970:INFO:CONSOLE(341)] "chrome.loadTimes() is deprecated, instead use standardized API: nextHopProtocol in Navigation Timing 2. https://www.chromestatus.com/features/5637885046816768. source: https://apis.google.com/_/scs/abc-stati ... i.loaded_0 (341)
[0518/171634.561:FATAL:url_util.cc(490)] Check failed: !scheme_registries_locked. Trying to add a scheme after the lists have been locked.
[0518/171709.294:INFO:media_foundation_video_encode_accelerator_win.cc(370)] Windows versions earlier than 8 are not supported.
[0518/171711.201:FATAL:dom_document_impl.cc(226)] Check failed: node_map_.empty().
[0518/171716.209:FATAL:url_util.cc(490)] Check failed: !scheme_registries_locked. Trying to add a scheme after the lists have been locked.
[0518/171812.191:INFO:media_foundation_video_encode_accelerator_win.cc(370)] Windows versions earlier than 8 are not supported.
[0518/171813.825:FATAL:dom_document_impl.cc(226)] Check failed: node_map_.empty().
[0518/171816.051:FATAL:url_util.cc(490)] Check failed: !scheme_registries_locked. Trying to add a scheme after the lists have been locked.
[0518/173626.819:INFO:media_foundation_video_encode_accelerator_win.cc(370)] Windows versions earlier than 8 are not supported.
[0518/173628.369:FATAL:dom_document_impl.cc(226)] Check failed: node_map_.empty().

My configuration:
Windows 7 ultimate
MSVS Community 2017 15.6.7

How can I use CefDomVisitor with current CEF versions?
How can I debug it or how I can get more info for investigation?
Artem
Newbie
 
Posts: 5
Joined: Fri May 18, 2018 9:20 am

Re: App crash when I use CefDomVisitor

Postby fddima » Fri May 18, 2018 10:26 am

Hello.

1. Why not latest stable branch, e.g. 66.0?

2. Documentation clearly states that you should not keep any references to dom nodes outside CefDomVisitor. E.g. inside visit method you should Dispose each obtained instance of CefDomNode or Document manually. There is currently no autodispose scope in this place yet.

3. According to log, hints above might not help... not sure, need make repro.

PS: I read above Root property. Hm. Debugging might help. Put debug CEF build, symbols, and in CEF.log should appear accurate fail stacktrace. For debugging, just land Debugger.Launch call before Root property access, but you jeed checkout corresponding CEF sources (see CEF build instruction how to checkout).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: App crash when I use CefDomVisitor

Postby fddima » Fri May 18, 2018 10:31 am

Also in most cases it is much better use JS to inspect DOM. CefDomVisitor API has unique specifics, but generally you should avoid using of this API part if other ways exist.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: App crash when I use CefDomVisitor

Postby Artem » Fri May 18, 2018 11:41 am

Hi, thank you for replay.

fddima wrote:1. Why not latest stable branch, e.g. 66.0?

I found branch in CEFGlue repo and download acceptable version of CEF binaries

fddima wrote:2. Documentation clearly states that you should not keep any references to dom nodes outside CefDomVisitor. E.g. inside visit method you should Dispose each obtained instance of CefDomNode or Document manually. There is currently no autodispose scope in this place yet.


Code: Select all
internal class DemoCefDomVisitor : CefDomVisitor
{
    protected override void Visit(CefDomDocument document)
    {
        File.WriteAllLines(
            "HackerNewsTitles.txt",
            GetHackerNewsTitles(document.Root)
        );
    }

    private IEnumerable<string> GetHackerNewsTitles(CefDomNode node)
    {
        if (IsHackerNewsTitle(node))
        {
            yield return node.FirstChild.InnerText;
        }

        CefDomNode child = node.FirstChild;
        while (child != null)
        {
            foreach (string title in GetHackerNewsTitles(child))
            {
                yield return title;
            }
            child = child.NextSibling;
        }
    }

    private bool IsHackerNewsTitle(CefDomNode node)
    {
        return
            node.NodeType == CefDomNodeType.Element &&
            node.ElementTagName == "TD" &&
            node.HasAttribute("class") &&
            node.GetAttribute("class") == "title" &&
            node.FirstChild.NextSibling != null;
    }
}


I don't keep any references to nodes and document

fddima wrote:3. According to log, hints above might not help... not sure, need make repro.


I can do it if needed

fddima wrote:Also in most cases it is much better use JS to inspect DOM. CefDomVisitor API has unique specifics, but generally you should avoid using of this API part if other ways exist.


Main goal of using CefDomVisitor is find elemnt and return boundin box.
I can use JS and V8 context normally for my purposes. Can you explain, why it is better to use JS instead CefDomDocument?
Artem
Newbie
 
Posts: 5
Joined: Fri May 18, 2018 9:20 am

Re: App crash when I use CefDomVisitor

Postby fddima » Fri May 18, 2018 2:10 pm

1. Master/default branch usually points to latest supported version.

2. You doesnt keep references directly, but wrapper objects do this until they GCed. Basically same as COM interop (RCW).

3. JS better because it doesnt uses this specific CEF API parts which on the edge between removal and must-have for compatibility and some unique functionality. Rest of cases as i say, better do in JS because simpler, more tools, querying dom ia simple, etc. As for bounding box, i'm not sure which box returns via CefDomNode, but if this coords inside frame - thdn same data you can get via JS. If it returns relative to viewport... Then good.

Reproduction is always welcome, but before, try collect accurate crash stack.

Thanks.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am


Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 14 guests