Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill chromium embedded framework subprocess?

in a PC game I have ingame browser used for news, virtual currency shop and social networks. It's built with quite fresh update of Chromium Embedded Framework. The problem is when I open a browser window (website is working fine there) and then close, for certain websites CEF sub-process doesn't finish. I also may continue hearing audio, if it was Youtube video, for example. I use offscreen rendering, other native windows are not created, only subprocesses. To close the browser window I remove all references to CefBrowser and call:

m_browser->GetHost()->CloseBrowser(true);

I also tried other ways to close/destroy/finalize that render subprocess, such as loading 'about:blank' before closing, but that was no help: process stayed awake, audio continued playing. Important note: it happens only on certain websites, which I suppose use some feature, that others don't. When I tried to disable JavaScript in CEF settings, the bug disappeared, but I need JS.

  1. Is there a way to force kill browser subprocess? (Notice that GetWindowHandle returns 0, because it does not have a window)
  2. Is there another way to correctly terminate browser which I don't know?
  3. What feature of the websites may cause such bug?

Thank you!

CEF runtime configuration: multi-process, single threaded message loop, with subprocess path, windowless rendering, no sandbox.

PC configuration: OS Windows 8, VS 2010, Chromium Embedded Framework version 3.3071, build 1649, C++ language.

like image 410
Juster Avatar asked Sep 01 '17 13:09

Juster


1 Answers

You should check your implementation of onbeforeunload.

CEF GeneralUsage writes about CefBrowserHost::CloseBrowser: The parent window then needs to call CloseBrowser(false) and wait for a second OS close event to indicate that the browser has allowed the close. The second OS close event will not be sent if the close is canceled by a JavaScript ‘onbeforeunload’ event handler or by the DoClose() callback.

And if you still want to just kill the sub-process , I would suggest you use the browser IPC message and exit at the app. At your game run

CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create(KILL_subprocess);
m_browser->SendProcessMessage(PID_RENDERER, msg);

and at the subprocess implement “OnProcessMessageReceived”:

if (msg->GetName() == KILL_subprocess)
{
    delete this;
    std::exit(EXIT_FAILURE);
}
like image 110
hamavreg Avatar answered Nov 15 '22 13:11

hamavreg