chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.09k stars 450 forks source link

Crashed When use load-extension with content_scripts #3654

Closed prettybxp closed 4 months ago

prettybxp commented 4 months ago

Describe the bug i found you add content_scripts support from 120.0.6099.0, but i not work, it will cause render crash. i test the extension in chrome, it work ok.

To Reproduce Steps to reproduce the behavior:

  1. build master branch cefclient
  2. run cefclient.exe cefclient.exe --load-extension=E:/extension/sample
  3. in the demo the manifest.json file look like this
    {
    "content_scripts": [ {
      "all_frames": true,
      "js": [ "content.static.js" ],
      "match_about_blank": true,
      "matches": [ "http://*/*", "https://*/*", "ftp://*/*", "file://*/*" ],
      "run_at": "document_start"
    } ],
    "manifest_version": 2,
    "name": "sample",
    "version": "1.1"
    }

and content.static.js code like this console.log("content.static")

  1. then, we will got a render process crash like this: crash at ExtensionInjectionHost::CanExecuteOnFrame the ExtensionWebViewHelper::Get(render_frame->GetWebView()) will return nullptr:

image

image

i try to fix it by:

diff --git extensions/renderer/extension_injection_host.cc extensions/renderer/extension_injection_host.cc
index d1cf50d7c6be2..195fb0119bfd1 100644
--- extensions/renderer/extension_injection_host.cc
+++ extensions/renderer/extension_injection_host.cc
@@ -53,9 +53,9 @@ PermissionsData::PageAccess ExtensionInjectionHost::CanExecuteOnFrame(
   // If the WebView is embedded in another WebView the outermost extension
   // origin will be set, otherwise we should use it directly from the
   // WebFrame's top origin.
-  auto outermost_origin =
+  auto outermost_origin = ExtensionWebViewHelper::Get(render_frame->GetWebView()) ?
       ExtensionWebViewHelper::Get(render_frame->GetWebView())
-          ->GetOutermostOrigin();
+             ->GetOutermostOrigin() : absl::nullopt;
   if (!outermost_origin) {
     outermost_origin = render_frame->GetWebFrame()->Top()->GetSecurityOrigin();
   }
-- 

but I want to know why it works in chrome

Expected behavior the page and extension loaded success.

Screenshots If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

magreenblatt commented 4 months ago

Extensions are generally not supported with the Alloy runtime. See https://github.com/chromiumembedded/cef/issues/1947#issuecomment-1465003373

You can use extensions with the Chrome runtime (add --enable-chrome-runtime command-line flag in cefclient).