CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

GetSource returns incomplete HTML

Open aradzu10 opened this issue 10 years ago • 9 comments

I'm using in my project Cefsharp. I want to get the html source of a page after the page done loading. So Im using this code:

    private void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
    {
        if (e.Frame.IsMain)
        {
            //chromeBrowser.ViewSource();
            chromeBrowser.GetSourceAsync().ContinueWith(taskHtml =>
            {
                var html = taskHtml.Result;
            });
        }
    }

And I saw that the line "chromeBrowser.ViewSource();" opens me a notepad with the source file. But I don't get the same "file"/text in my html variable. I would like to get what Im getting from the ViewSource() and not from GetSourceAsync().

How can I do that?

aradzu10 avatar Nov 13 '16 11:11 aradzu10

This does not sound like a bug, although as this is a wrapper it would most likely be upstream issue. So I am not sure why you have reported it as such. If you have a question, you should ask it on Gitter, post on StackOverflow or use http://magpcss.org/ceforum/ (for questions specific to CEF).

GrabzIt avatar Dec 01 '16 11:12 GrabzIt

What URL reproduces this problem? What version are you using? Please use the Bug Report template when posting an issue. https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md#bug-report

Looking at the CEF implementation it's likely timing related, try adding a menu item to your app that gets the source, wait a few seconds for your page to load before clicking and see what result you get.

You can call GetSource on the frame directly and use your own implementation of IStringVisitor https://github.com/cefsharp/CefSharp/blob/cefsharp/53/CefSharp/IFrame.cs#L75 to debug the problem, your probably best downloading the project source to do this.

amaitland avatar Jan 09 '17 01:01 amaitland

Closing due to lack of feedback.

amaitland avatar Jan 16 '17 03:01 amaitland

As this appears to be a bug in CEF, someone will have to post on http://magpcss.org/ceforum/ It's important that you provide a URL that demonstrates your problem.

Once you've posted on http://magpcss.org/ceforum/ then post a link here.

amaitland avatar Apr 17 '17 12:04 amaitland

I've created a post on Supoort Forum, but it needs to be approved it says. After that, I'll post the link here.

YSFKBDY avatar Apr 17 '17 13:04 YSFKBDY

http://magpcss.org/ceforum/viewtopic.php?f=6&t=15063

YSFKBDY avatar Apr 17 '17 16:04 YSFKBDY

I am having the same problem. The HTML content from Viewsource and GetSourceAsync are different. and it looks like the one returned on GetsourceAsync is incomplete. How did you solve it?

zankhanarana9 avatar Jul 17 '19 18:07 zankhanarana9

Yes, this is bug, in the latest version as of now. Here is a url example... https://www.mercari.com/search/?itemStatuses=1&keyword=dam%20troll&sortBy=2 ...but it happens with any large page. The View Source (manual in the ui) and a GetSourceAsync (sp?) in code both are not working as they should. That url has hundreds of listings. But the View source returns only about 30 at the most. Tried browser.refresh no luck, tried page all the way down no luck, tried forced pause after ever page down no luck, tried page-all-the-way-down and then page-all-the-way-up and then view source (or getsourceasync) no luck. This is definitely a bug, or "view source" and "getsourceasync" need a new (non-standard) definition. Anyway, I would love to see a fix, or be proven wrong on this, but such as it is it definitely looks like a bug to me. Thanks. -- Mark

mkamoski avatar Sep 17 '22 20:09 mkamoski

The View Source (manual in the ui) and a GetSourceAsync (sp?) in code both are not working as they should.

CefSharp is just a wrapper around the Chromium Embedded Framework.

  • For ViewSource we simply call the underlying ViewSource method.
  • For GetSourceAsync we call GetSource and resolve the Task<string> with the StringVisitor response.

If code changes are required then they would need to be made in CEF or Chromium.

If you can reliably reproduce the issue with the current supported version then please create an issue on the CEF Issue Tracker.

For reference

  • https://github.com/chromiumembedded/cef/blob/f2206b8dbc4c28be576dc472680d4c9e5e181de7/libcef/renderer/frame_impl.cc#L763
  • https://github.com/chromiumembedded/cef/blob/21cf732e7fdac8a8d9d94dc9f97becd4233efab9/libcef/renderer/blink_glue.cc#L112

amaitland avatar Sep 26 '22 02:09 amaitland