Faster way of getting an html element than ViewSource()?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Faster way of getting an html element than ViewSource()?

Postby eugor » Fri Nov 17, 2017 10:34 am

The ViewSource() method seems to take more than 30ms on big sites for what is basically copying a string.
Is there any faster way to checking if an html element exists (maybe with a custom handler)?
eugor
Newbie
 
Posts: 5
Joined: Fri Nov 17, 2017 10:26 am

Re: Faster way of getting an html element than ViewSource()?

Postby magreenblatt » Fri Nov 17, 2017 10:57 am

Can you provide more context about what you're trying to do?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Faster way of getting an html element than ViewSource()?

Postby eugor » Fri Nov 17, 2017 11:46 am

I'm observing 10+ websites in real time and reloading the source every time I'm checking values of certain html elements.
It's mostly dynamic content (like a countdown) but switching to a different site is also sometimes required.

Every browser check takes 30ms for loading the source and another 10ms for looking at the values.
I'd like to refresh the content faster to observe changes as soon as possible and the ViewSource() method seems like the biggest bottleneck so far.
Last edited by eugor on Fri Nov 17, 2017 11:49 am, edited 1 time in total.
eugor
Newbie
 
Posts: 5
Joined: Fri Nov 17, 2017 10:26 am

Re: Faster way of getting an html element than ViewSource()?

Postby magreenblatt » Fri Nov 17, 2017 11:49 am

Have you considered injecting JavaScript into the page? See https://bitbucket.org/chromiumembedded/ ... javascript
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Faster way of getting an html element than ViewSource()?

Postby eugor » Fri Nov 17, 2017 12:38 pm

Oh wow, that seems to work really well (<1ms) so far. Thanks!

Here is my cefsharp code I used for testing, in case someone needs it:

Code: Select all
       
public async Task<bool> EleExists()
        {
            string script = "(function() { return document.getElementsByClassName('playerIcon').length; })();";
            string returnValue = "0";
            await browser.EvaluateScriptAsync(script).ContinueWith(x =>
            {
                if (x.Result.Success && x.Result.Result != null)
                    returnValue = x.Result.Result.ToString();
            });
            return (int.Parse(returnValue) > 0);
        }
eugor
Newbie
 
Posts: 5
Joined: Fri Nov 17, 2017 10:26 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 15 guests