Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Add Chrome Extension Support #2497

Closed
1 task done
amaitland opened this issue Aug 29, 2018 · 15 comments
Closed
1 task done

Feature Request - Add Chrome Extension Support #2497

amaitland opened this issue Aug 29, 2018 · 15 comments

Comments

@amaitland
Copy link
Member

amaitland commented Aug 29, 2018

CEF added support for extensions in https://bitbucket.org/chromiumembedded/cef/issues/1947/add-support-for-chrome-extensions

Only some of the built in API's are exposed, load chrome://extensions-support in the browser to see which API's are supported.

There are quite a few methods and handlers that need to be added (not a complete list)

http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRequestContext.html#LoadExtension(constCefString&,CefRefPtr%3CCefDictionaryValue%3E,CefRefPtr%3CCefExtensionHandler%3E)
http://magpcss.org/ceforum/apidocs3/projects/(default)/CefExtensionHandler.html

  • LoadExtension must be called on CEF UI thread, as no result is returned post the method call to the correct thread.
@davisford
Copy link

Anyone gauge what it will take to get this working? I might be interested in submitting a PR. I really need this soon.

@amaitland
Copy link
Member Author

Only some of the built in API's are exposed, load chrome://extensions-support in the browser to see which API's are supported.

@davisford If you haven't already I'd recommend confirming that CEF implements all the Extension APIs you require. If something is missing then you'd need to have it implemented in CEF first. A nice compact example of adding an Extension API to CEF is https://bitbucket.org/chromiumembedded/cef/commits/dddfce4

@davisford
Copy link

@amaitland yes, I aim to fire up and look at chrome://extensions-support but I'm currently just using a background script with a fairly simple content script, so I'm pretty sure what I'm doing would work. Looks like support for extensions has been in CEF for quite some time now, but need .NET apis wrappers to install the extension? I'm mainly interested in installing an unpacked extension in developer mode.

@amaitland
Copy link
Member Author

Looks like support for extensions has been in CEF for quite some time now

It has, though I don't see a lot of support requests on https://magpcss.org/ceforum/index.php for it, so it either works flawlessly or it's not that well used. (Just an observation, I have yet to try the API).

There are quite a few pieces that need to be implemented to expose the full API, a PR containing a partial implementation is probably acceptable if the core functionality is present.

@amaitland
Copy link
Member Author

#2613 has been merged, it's now possible to load a Chrome Extension, remembering that CEF only supports a subset of the Chrome Extension APIs at this time. The WinForms.Example project contains a working example.

Only outstanding task is to marshal LoadExtension on the CEF UI thread, I had an implementation that compiled successfully in VS2017, failed using VS2015, so it was reverted for now. Will look at implementing before official 71.0.0 release, I will release 71.0.0-pre01 as is, it's pretty trivial to manually marshal the call onto the CEF UI thread.

@ahvahsky2008
Copy link

@amaitland thx for reply) i have extension. Unzip it. two js files.
https://pastebin.com/i1QxxNdL background.js
https://pastebin.com/Q0dax7Qy content.js

I load it, but i think browser not see this code

void IExtensionHandler.OnExtensionLoaded(IExtension extension)
        {
            //var manifest = extension.Manifest;
            //var browserAction = manifest["browser_action"].GetDictionary();
            //if (browserAction.ContainsKey("default_popup"))
            //{
            //    var popupUrl = browserAction["default_popup"].GetString();

            //    popupUrl = "chrome-extension://" + extension.Identifier + "/" + popupUrl;

            //    LoadExtensionPopup?.Invoke(popupUrl);
            //}

                var popupUrl = "chrome-extension://" + extension.Identifier + "/";

                LoadExtensionPopup?.Invoke(popupUrl);
        }

extension url https://chrome.google.com/webstore/detail/%D1%80%D0%B0%D1%81%D1%88%D0%B8%D1%80%D0%B5%D0%BD%D0%B8%D0%B5-%D0%B4%D0%BB%D1%8F-%D0%BF%D0%BB%D0%B0%D0%B3%D0%B8%D0%BD%D0%B0-%D0%B3%D0%BE/pbefkdcndngodfeigfdgiodgnmbgcfha?hl=ru&authuser=1

@amaitland
Copy link
Member Author

@ahvahsky2008 download the example extension provided, confirm that it loads and you can get it working. As stated above CEF only supports a small set of the Chrome extension APIs, only a very limited set of extensions will work at this time.

@ahvahsky2008
Copy link

@amaitland i downloaded it, but its not working

@amaitland
Copy link
Member Author

amaitland commented Jan 8, 2019

A few notes when loading extensions

  • crx files must be extracted to disk before they can be loaded (in Chrome the crx file is extracted into C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\Extensions\)
  • For extensions that display popup windows you must query the manifest and manually open the resulting url in a new ChromiumWebBrowser instance. The example has a very basic demo of this.
  • The CEF Sample Application(cefclient) can be used for testing of extensions, you can use
#Test with the built in example
cefclient --load-extension=set_page_color

#Load extension from disk
cefclient --load-extension=c:\path\to\my\extension

The Sample Application can be downloaded from http://opensource.spotify.com/cefbuilds/index.html

Chrome sample extensions are at https://developer.chrome.com/extensions/samples

@cefsharp cefsharp deleted a comment from ahvahsky2008 Jan 8, 2019
@cefsharp cefsharp deleted a comment from ahvahsky2008 Jan 8, 2019
@cefsharp cefsharp deleted a comment from Spiderpig86 Jan 8, 2019
@mcsnb
Copy link

mcsnb commented Jan 9, 2019

@ahvahsky2008 download the example extension provided, confirm that it loads and you can get it working. As stated above CEF only supports a small set of the Chrome extension APIs, only a very limited set of extensions will work at this time.

Is there any plan to do which api first? I notice that only four APIs are currently supported. How about runtime and desktopCapture? I really need these two APIs.

@amaitland
Copy link
Member Author

Is there any plan to do which api first? I notice that only four APIs are currently supported. How about runtime and desktopCapture? I really need these two APIs.

@mcsnb When CEF adds support for those API's then they will become available in CefSharp. You can track the upstream progress at https://bitbucket.org/chromiumembedded/cef/issues/1947/add-support-for-chrome-extensions

This issue is purely to track the progress of exposing the relevant API methods, and will be closed shortly as it's 99% complete.

@mcsnb
Copy link

mcsnb commented Jan 9, 2019

Is there any plan to do which api first? I notice that only four APIs are currently supported. How about runtime and desktopCapture? I really need these two APIs.

@mcsnb When CEF adds support for those API's then they will become available in CefSharp. You can track the upstream progress at https://bitbucket.org/chromiumembedded/cef/issues/1947/add-support-for-chrome-extensions

This issue is purely to track the progress of exposing the relevant API methods, and will be closed shortly as it's 99% complete.

@amaitland Thx. It seems that the progress is very slow. T_T

@amaitland
Copy link
Member Author

LoadExtension will now post onto the CEF UI thread automatically.

Other methods like DidLoadExtension still need to be explicitly called on the UI thread.

Closing this issue as the API is now complete from a CefSharp point of view.

@cefsharp cefsharp locked as resolved and limited conversation to collaborators May 4, 2020
@amaitland
Copy link
Member Author

The WPF example how has a demo of loading the same extension as the WinForms example, added in commit d6ca253

@amaitland
Copy link
Member Author

amaitland commented May 5, 2020

If you require assistance then please ask questions on the Chromium Embedded Framework(CEF) Forum.

You MUST confirm that CEF supports the Extension API's required by your Extension. If it does not then you will be unable to load the Extension.

Details for testing with the CEF Sample Application are listed above in #2497 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants