cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.87k stars 2.92k forks source link

Extension Option Pages fail to load with Chrome runtime in WinForms or Wpf.HwndHost #4963

Open mitchcapper opened 3 weeks ago

mitchcapper commented 3 weeks ago

Is there an existing issue for this?

CefSharp Version

129.0.980

Operating System

Windows 10

Architecture

x64

.Net Version

.net 6.0

Implementation

WinForms

Reproduction Steps

To the WinForm Sample netcore app Program.cs add: CefSharp.CefSharpSettings.RuntimeStyle = CefRuntimeStyle.Chrome; Run the WinForm sample app in .net 6 mode

Install any extension that has options by visiting the store page ie: https://chromewebstore.google.com/detail/shortcuts-for-google/baohinapilmkigilbbbcccncoljkdpnd

will prompt to download package can save anywhere it will still install will crash some can ignore just restart now go to chrome://extensions details on the extension and then click options

should get a crash

Expected behavior

not crash show options page

Actual behavior

enable settings.CefCommandLineArgs.Add("renderer-startup-dialog");

to attach to it on spawn (don't need to attach until the one right after you click options)

chrome-extension://baohinapilmkigilbbbcccncoljkdpnd/views/options.html

The crash happens in libcef_dll\cpptoc\render_process_handler_cpptoc.cc

void CEF_CALLBACK render_process_handler_on_browser_created(
    struct _cef_render_process_handler_t* self,
    cef_browser_t* browser,
    struct _cef_dictionary_value_t* extra_info) {
  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  DCHECK(self);
  if (!self) {
    return;
  }
  // Verify param: browser; type: refptr_diff
  DCHECK(browser);
  if (!browser) {
    return;
  }
  // Unverified params: extra_info

  // Execute
  CefRenderProcessHandlerCppToC::Get(self)->OnBrowserCreated(
      CefBrowserCToCpp::Wrap(browser),
      CefDictionaryValueCToCpp::Wrap(extra_info));
}

The final line there. extra_info is null, browser is not, both wraps seems to succeed. The Get succeeds. Single stepping right after the final wrap (in theory when OnBrowserCreated is called) you get the crash but you are already in the fatal log message.

The log on verbose shows:

[9824:49364:1023/162019.956:ERROR:cpu_probe_win.cc(112)] PdhAddEnglishCounter failed: Error (0x13D) while retrieving error. (0xC0000BB8)
Fatal error. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
   at <Module>.cef.logging.LogMessage.{dtor}(cef.logging.LogMessage*)
   at <Module>.cef.logging.LogMessage.{dtor}(cef.logging.LogMessage*)
   at <Module>.scoped_refptr<CefDictionaryValue>.->(scoped_refptr<CefDictionaryValue>*)
   at <Module>.CefSharp.BrowserSubprocess.CefAppUnmanagedWrapper.OnBrowserCreated(CefSharp.BrowserSubprocess.CefAppUnmanagedWrapper*, scoped_refptr<CefBrowser>*, scoped_refptr<CefDictionaryValue>*)
   at <Module>.CefExecuteProcess(CefMainArgs*, scoped_refptr<CefApp>*, Void*)
   at <Module>.CefExecuteProcess(CefMainArgs*, scoped_refptr<CefApp>*, Void*)
   at CefSharp.BrowserSubprocess.SubProcess.Run()
   at CefSharp.BrowserSubprocess.BrowserSubprocessExecutable.Main(System.Collections.Generic.IEnumerable`1<System.String>, CefSharp.RenderProcess.IRenderProcessHandler)
   at CefSharp.BrowserSubprocess.Program.Main(System.String[])
[9824:51708:1023/162204.958:ERROR:cpu_probe_win.cc(112)] PdhAddEnglishCounter failed: Error (0x13D) while retrieving error. (0xC0000BB8)

Regression?

probably not

Known Workarounds

unknown work around

Does this problem also occur in the CEF Sample Application

No

Other information

Trying cefclient with:

./cefclient.exe --no-sandbox --lang=en-US --remote-debugging-port=8088 --uncaught-exception-stack-size=10 --use-chrome-style-window --disable-features=EnableHangWatcher --disable-chrome-login-prompt --hide-crash-restore-bubble --enable-unsafe-extension-debugging --enable-experimental-extension-apis --no-proxy-server --cache-path=C:/CacheMeIfYouCan/  --url=chrome://extensions

does not repro the same error, everything works. Given the lack of cefclient reproducing it and the lack of debug stepping there or something to break down no idea what one would debug further.

amaitland commented 3 weeks ago

There are some extensions that will only work with the full Chromium UI. I think this is likely one of those.

--use-chrome-style-window

I think that'll use the Chromium UI. Does it show the Chromium menu? e.g. three dots?

Can you try with --use-native instead? That should match Chrome Runtime embedded into a native window.

mitchcapper commented 2 weeks ago

OK I made a foolish error and must have been attaching to the render process with native only debugging. I noticed just hitting windows key + N with the above cli options to create a new window appears and would then crash. I did a procdump as with these options I didn't even get a chance to attach before crash.

ExtraInfo is null like I mentioned but cefsharp doesn't expect this: image

I saw this once before for reasons I don't recall but at the time I thought I traced that it shouldn't have been null.

Officially the docs say

|extra_info| is an optional read-only value originating from CefBrowserHost::CreateBrowser(), CefBrowserHost::CreateBrowserSync(), CefLifeSpanHandler::OnBeforePopup() or CefBrowserView::CreateBrowserView().

In this case tracing back up I see CreateWebView is called with a nullptr for params.

We do check IsPopup and that comes from cef it seems so not sure if there is another property we should be checking.:

 // CefRenderProcessHandler
 void CefAppUnmanagedWrapper::OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extraInfo)
 {
     auto wrapper = gcnew CefBrowserWrapper(browser);
     _onBrowserCreated->Invoke(wrapper);

     //Multiple CefBrowserWrappers created when opening popups
     _browserWrappers->TryAdd(browser->GetIdentifier(), wrapper);

     //For the main browser only we check LegacyBindingEnabled and
     //load the objects. Popups don't send this information and checking
     //will override the _legacyBindingEnabled field
     if (!browser->IsPopup() && extraInfo && extraInfo.get() != NULL )
     {
         _legacyBindingEnabled = extraInfo->GetBool("LegacyBindingEnabled");

works and works without the two additional CLI args for multiple crashes from before.

amaitland commented 2 weeks ago

works and works without the two additional CLI args for multiple crashes from before.

Nice work!

Have added check in commit https://github.com/cefsharp/CefSharp/commit/c44f56f5af02d808d21fd3945a300761561a991a

Included in the 130.1.90 release.

Is there anything else required for this?