I've managed to install an extension automatically by adding the following
snippet to "chrome\browser\chrome_browser_main.cc":
void InstallMyExtension () {
LOG(INFO) << "InstallMyExtension():";
base::FilePath path(
L"C:\\my_extension_dir\");
LOG(INFO) << "InstallMyExtension(): Installing extension from path"
<< path;
base::FilePath kiwi_extension_crx_name(L"my_extension.crx");
scoped_refptr<extensions::CrxInstaller> crx_installer(
extensions::CrxInstaller::CreateSilent(extension_service));
crx_installer->set_install_immediately(true);
LOG(INFO) << "InstallMyExtension(): Installing from path: "
<< path.Append(kiwi_extension_crx_name);
crx_installer->InstallCrx(path.Append(kiwi_extension_crx_name));
}
Profile* CreatePrimaryProfile(...) {
...
InstallMyExtension(profile);
return profile;
}
This works nicely; the extension is installed but not enabled.
I tried enabling it by changing: "chrome\browser\extensions\crx_installer.cc":
in the last step (intuitively since the extension is assumed installed):
void CrxInstaller::CleanupTempFiles() {
ExtensionService* service = service_weak_.get();
if (!service || service->browser_terminating())
return;
service->GrantPermissionsAndEnableExtension(extension());
...
}
but I get an error like:
[ERROR:socket_posix.cc(144)] bind() returned an error, errno=98: Address already in use (98)
[ERROR:unix_domain_server_socket_posix.cc(98)] Could not bind unix domain socket to chrome_devtools_remote (with abstract namespace): Address already in use (98)
[ERROR:devtools_http_handler.cc(292)] Cannot start http server for devtools. Stop devtools.
I'm not exactly sure what address is already in use. Is there another way of enabling extensions?
I also tried setting the completion callback:
scoped_refptr<extensions::CrxInstaller> crx_installer(
extensions::CrxInstaller::CreateSilent(extension_service));
crx_installer->set_install_immediately(true);
crx_installer->set_installer_callback(
base::BindOnce([](const base::Optional<extensions::CrxInstallError>&
error) {
}));
but I can't send parameters to it; it needs a browser context/profile in order to get the extension service.
Any thoughts?