OnLoadEnd called multiple times

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.

OnLoadEnd called multiple times

Postby yinteresting » Fri Sep 15, 2017 10:24 am

So I am trying to access DOM when the render process completes rendering the content of the browser.

But I found that OnLoadEnd will be called multiple times. Is there another function that will be called after the render process completely finish the rendering process other than CefLoadHandler::OnLoadEnd()?

I noticed that for Google Website, this OnLoadEnd will be called once. But other websites, like https://www.rhs.org.uk/, the OnLoadEnd will be called endless times.

What I did is the following:

// const char parseDOMMessage[] = "RenderProcessNowParsingDOM";
void CDlgWebView::OnLoadEnd( int httpStatusCode)
{
// Browser process will call OnLoadEnd to indicate the completion of render process
// We will send a message back to the render process to parse the DOM
if (fCefBrowser) {
CefRefPtr<CefProcessMessage> parseMessage =
CefProcessMessage::Create(parseDOMMessage);
fCefBrowser->SendProcessMessage(PID_RENDERER, parseMessage);
}
}

bool DemoCefApp::DemoCefRenderProcessHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
if (message->GetName() == "RenderProcessNowParsingDOM") {
CefRefPtr<CefFrame> mainFrame = browser->GetMainFrame();
CefRefPtr<CefDOMVisitor> visitor = new DemoCefDomVisitor();
mainFrame->VisitDOM(visitor);
return true;
}
return false;
}

void DemoCefApp::DemoCefDomVisitor::Visit(CefRefPtr<CefDOMDocument> document) {
CefString title;
if (document) {
title = document->GetTitle();
std::string t = title.ToString();
// convert to std::wstring
std::wstring ws;
ws.assign(t.begin(), t.end());
LPCWSTR pcwstr = ws.c_str();
OutputDebugString(pcwstr); // it was printed out the title of the URL endless times
}

Any help please?
yinteresting
Newbie
 
Posts: 5
Joined: Thu Sep 07, 2017 1:53 pm

Re: OnLoadEnd called multiple times

Postby salvadordf » Fri Sep 15, 2017 11:00 am

Hi,

Check if you are receiving the OnLoadEnd from the main frame.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: OnLoadEnd called multiple times

Postby magreenblatt » Fri Sep 15, 2017 2:45 pm

You can also use OnLoadingStateChange
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

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