Load unpacked Chrome extension programmatically

前端 未结 4 2229
广开言路
广开言路 2021-02-14 00:31

Is it possible to load and unload unpacked Chrome extensions from the Command Line?

4条回答
  •  Happy的楠姐
    2021-02-14 01:09

    Try to kill all existing instances of Chrome from task manager : TASKKILL /IM chrome.exe /F and then chrome.exe --load-extension=path/to/extension should work

    This working C# code for console application can help

    class Program
        {
            static void Main(string[] args)
            {
                Process cmd = new Process();
    
                cmd.StartInfo.FileName = "cmd.exe";
                cmd.StartInfo.RedirectStandardInput = true;
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.CreateNoWindow = true;
                cmd.StartInfo.UseShellExecute = false;
    
                cmd.Start();
                //kill all chrome instances
                cmd.StandardInput.WriteLine("TASKKILL /IM chrome.exe /F");
                //path to chrome.exe
                cmd.StandardInput.WriteLine("cd C:\\Program Files (x86)\\Google\\Chrome\\Application");
                //load extension
                cmd.StandardInput.WriteLine("chrome.exe --load-extension={path-to-extension}");
    
                cmd.StandardInput.Flush();
                cmd.StandardInput.Close();
                Console.WriteLine(cmd.StandardOutput.ReadToEnd());
    
            }
        }
    

提交回复
热议问题