I need some help to load unpacked (or packed if you know how I can do it) form directory.
I've searched a lot but I don't find anything updated for that.
I'm trying to call this function:
this.browser.RequestContext.LoadExtensionFromDirectory(Directory.GetCurrentDirectory() +
"/vendors/static/fcfhplploccackoneaefokcmbjfbkenj", ???????????? );
But I don't find a way to get the IExtensionHandler
described in the documentation:
RequestContextExtensions.LoadExtensionsFromDirectory
I have a simple CefSharp embedded browser in a Form, where I'm trying to load the extension.
I can't figure how to get this IExtensionHandler
.
Here is my code:
public partial class MainEmbedBrowser : Form
{
private string ID;
private ChromiumWebBrowser browser;
public MainEmbedBrowser(string url, string combo)
{
InitializeComponent();
this.browser = new ChromiumWebBrowser("localhost", new RequestContext());
//this.browser.RequestContext.LoadExtensionFromDirectory(Directory.GetCurrentDirectory() + "/vendors/static/fcfhplploccackoneaefokcmbjfbkenj", extensionHandler);
this.Controls.Add(browser);
this.browser.Load("https://google.com");
this.browser.Height = this.Height;
this.browser.Width = this.Width;
this.Show();
}
}
If someone can help me, thanks in advance
I have not got any experience with this functionality, however, from looking at the documentation, for your "question marks" you will need to supply a class that implements the IExtensionHandler interface.. So, first of all you will need to create something like this:
public class MyExtHandler : IExtensionHandler
{
bool CanAccessBrowser(IExtension extension,IBrowser browser,bool includeIncognito,IBrowser targetBrowser)
{
return true;
}
IBrowser GetActiveBrowser(IExtension extension,IBrowser browser,bool includeIncognito)
{
return browser;
}
bool GetExtensionResource(IExtension extension,IBrowser browser,string file, IGetExtensionResourceCallback callback)
{
return true;
}
bool OnBeforeBackgroundBrowser(IExtension extension, string url, IBrowserSettings settings)
{
return true;
}
bool OnBeforeBrowser(IExtension extension,IBrowser browser,IBrowser activeBrowser,int index,string url,bool active,IWindowInfo windowInfo,IBrowserSettings settings)
{
return true;
}
void OnExtensionLoaded(IExtension extension)
{
}
void OnExtensionLoadFailed(CefErrorCode errorCode)
{
}
void OnExtensionUnloaded(IExtension extension)
{
}
}
Then, when the functions from that interface get called, you can decided what you want to do with them in your concrete class. For now I have just set them to return defaults.
Once you have your class defined, you can create an instance so that you can pass through to the line of code you have above. Something like:
var myExtHandler = new MyExtHandler();
this.browser.RequestContext.LoadExtensionFromDirectory(Directory.GetCurrentDirectory() + "/vendors/static/fcfhplploccackoneaefokcmbjfbkenj",myExtHandler );
I hope this helps gets you started. Apart from the above code I have no additional experience here.