[Solved] How to close browser with Off Screen Rendering

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.

[Solved] How to close browser with Off Screen Rendering

Postby pingu7931 » Mon May 15, 2017 11:36 am

CEF 3.3029.1617.gaf831b6 Windows 7 x64

Hi

I have switched from a working Windowed implementation to a Windowless (OSR) implementation by simple implementation of the CefRenderHandler methods as per the documentation. All working fine for valid URLs.

The problem I have now is that as I was calling browser->GetHost()->CloseBrowser() in after my implementation of CefLoadHandler::OnLoadError() but it seems the renderer is still active and causes an access violation at the DCHECK below. This seems to only occur when the URL is unreachable and it crashes the entire browser process and any other URL requests it may have been processing - we're stress testing. If I don't close the browser - all is fine.

Hoping this is something straightforward that an experienced eye can spot.

Thanks in advance.

Code: Select all
void NavigatorImpl::RecordNavigationMetrics(
    const LoadCommittedDetails& details,
    const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
    SiteInstance* site_instance) {
  DCHECK(site_instance->HasProcess());

Stack trace:
Code: Select all
>   libcef.dll!content::NavigatorImpl::RecordNavigationMetrics(const content::LoadCommittedDetails & details, const FrameHostMsg_DidCommitProvisionalLoad_Params & params, content::SiteInstance * site_instance) Line 1194   C++
    libcef.dll!content::NavigatorImpl::DidNavigate(content::RenderFrameHostImpl * render_frame_host, const FrameHostMsg_DidCommitProvisionalLoad_Params & params, std::unique_ptr<content::NavigationHandleImpl,std::default_delete<content::NavigationHandleImpl> > navigation_handle) Line 716   C++
    libcef.dll!content::RenderFrameHostImpl::OnDidCommitProvisionalLoad(const IPC::Message & msg) Line 1306   C++
    libcef.dll!content::RenderFrameHostImpl::OnMessageReceived(const IPC::Message & msg) Line 689   C++
    libcef.dll!content::RenderProcessHostImpl::OnMessageReceived(const IPC::Message & msg) Line 2100   C++
    libcef.dll!IPC::ChannelProxy::Context::OnDispatchMessage(const IPC::Message & message) Line 330   C++
    libcef.dll!base::internal::RunMixin<base::Callback<void __cdecl(void),0,0> >::Run() Line 68   C++
    libcef.dll!base::debug::TaskAnnotator::RunTask(const char * queue_function, base::PendingTask * pending_task) Line 61   C++
    libcef.dll!base::MessageLoop::RunTask(base::PendingTask * pending_task) Line 421   C++
    libcef.dll!base::MessageLoop::DoWork() Line 524   C++
    libcef.dll!base::MessagePumpForUI::DoRunLoop() Line 174   C++
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate) Line 58   C++
    libcef.dll!base::RunLoop::Run() Line 38   C++
    libcef.dll!CefBrowserMessageLoop::RunMessageLoop() Line 128   C++

Last edited by pingu7931 on Tue May 16, 2017 7:24 am, edited 2 times in total.
pingu7931
Techie
 
Posts: 21
Joined: Thu Dec 01, 2016 4:43 am

Re: How to close browser with Off Screen Rendering

Postby magreenblatt » Mon May 15, 2017 1:25 pm

Does it crash in a Release build of libcef? You can probably call CloseBrowser asynchronously (using CefPostTask) to work around the problem.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: How to close browser with Off Screen Rendering

Postby pingu7931 » Tue May 16, 2017 5:57 am

Hi Marshall

Thanks for replying.

Yes it also crashes in the release build.
Only for ERR_NAME_NOT_RESOLVED (-105) as far as I can currently establish

My current close logic already uses CefPostTask as follows (CefLifespanHandler::DoClose returns false incidentally which should immediately close the browser):
Code: Select all
   void BrowserManager::CloseBrowser(CefRefPtr<CefBrowser> browser)
   {
      if (!CefCurrentlyOn(TID_UI)) {
         CefPostTask(TID_UI, base::Bind(&BrowserManager::CloseBrowser, this, browser));
         return;
      }
      browser->GetHost()->CloseBrowser(true);
   }


Here's the call stack for release:

Code: Select all
    libcef.dll!content::WebContentsImpl::DidNavigateMainFramePostCommit(content::RenderFrameHostImpl * render_frame_host, const content::LoadCommittedDetails & details, const FrameHostMsg_DidCommitProvisionalLoad_Params & params) Line 3465   C++
>   libcef.dll!content::NavigatorImpl::DidNavigate(content::RenderFrameHostImpl * render_frame_host, const FrameHostMsg_DidCommitProvisionalLoad_Params & params, std::unique_ptr<content::NavigationHandleImpl,std::default_delete<content::NavigationHandleImpl> > navigation_handle) Line 722   C++
    libcef.dll!content::RenderFrameHostImpl::OnDidCommitProvisionalLoad(const IPC::Message & msg) Line 1306   C++
    libcef.dll!content::RenderFrameHostImpl::OnMessageReceived(const IPC::Message & msg) Line 689   C++
    libcef.dll!content::RenderProcessHostImpl::OnMessageReceived(const IPC::Message & msg) Line 2100   C++
    libcef.dll!IPC::ChannelProxy::Context::OnDispatchMessage(const IPC::Message & message) Line 330   C++
    libcef.dll!base::internal::RunMixin<base::Callback<void __cdecl(void),0,0> >::Run() Line 68   C++
    libcef.dll!base::debug::TaskAnnotator::RunTask(const char * queue_function, base::PendingTask * pending_task) Line 61   C++
    libcef.dll!base::MessageLoop::RunTask(base::PendingTask * pending_task) Line 421   C++
    libcef.dll!base::MessageLoop::DoWork() Line 524   C++
    libcef.dll!base::MessagePumpForUI::DoRunLoop() Line 174   C++
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate) Line 58   C++
    libcef.dll!base::RunLoop::Run() Line 38   C++
pingu7931
Techie
 
Posts: 21
Joined: Thu Dec 01, 2016 4:43 am

Re: How to close browser with Off Screen Rendering

Postby pingu7931 » Tue May 16, 2017 7:23 am

Okay I've fixed it in the way I think you meant. Where I need to close a browser I call CefPostTask(TID_UI, base::Bind(&BrowserManager::CloseBrowser, this, browser)); - I.e. my wrapper around the close logic

In my previous implementation and we were currently on the TID_UI then the close would be called synchronously.

As this was working in windowed mode fine I guess it's a quirk of OSR
pingu7931
Techie
 
Posts: 21
Joined: Thu Dec 01, 2016 4:43 am

Re: [Solved] How to close browser with Off Screen Rendering

Postby magreenblatt » Tue May 16, 2017 8:12 am

Yes, it sounds like a bug in OSR. Please file an issue and link back to this thread.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: [Solved] How to close browser with Off Screen Rendering

Postby pingu7931 » Tue May 16, 2017 8:29 am

Many thanks
Set it as minor framework bug as I could work around it.

https://bitbucket.org/chromiumembedded/cef/issues/2170/cefbrowserhost-closebrowser-causes
pingu7931
Techie
 
Posts: 21
Joined: Thu Dec 01, 2016 4:43 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 42 guests