Пример #1
0
        public static int Main(string[] args)
        {
            const string testUrl = "https://www.google.com/";

            Console.WriteLine("This example application will load {0}, take a screenshot, and save it to your desktop.", testUrl);
            Console.WriteLine("You may see Chromium debugging output, please wait...");
            Console.WriteLine();

#if NETCOREAPP
            //We are using our current exe as the BrowserSubProcess
            //Multiple instances will be spawned to handle all the
            //Chromium proceses, render, gpu, network, plugin, etc.
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);
            if (result > 0)
            {
                return(result);
            }
#endif

            var settings = new CefSettings()
            {
                //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
            };

#if NETCOREAPP
            //We use our Applications exe as the BrowserSubProcess, multiple copies
            //will be spawned
            //TODO: The OffScreen implementation is crashing on Exit (WPF/WinForms are working fine).
            //So for now this is commented out and the old .Net CefSharp.BrowserSubProcess.exe
            //is used.
            //var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            //settings.BrowserSubprocessPath = exePath;
#endif

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            // Create the offscreen Chromium browser.
            browser = new ChromiumWebBrowser(testUrl);

            // An event that is fired when the first page is finished loading.
            // This returns to us from another thread.
            browser.LoadingStateChanged += BrowserLoadingStateChanged;

            // We have to wait for something, otherwise the process will exit too soon.
            Console.ReadKey();

            // Clean up Chromium objects.  You need to call this in your application otherwise
            // you will get a crash when closing.
            Cef.Shutdown();

            return(0);
        }
Пример #2
0
        public static int Main(string[] args)
        {
            //For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

#if NETCOREAPP
            //We are using our current exe as the BrowserSubProcess
            //Multiple instances will be spawned to handle all the
            //Chromium proceses, render, gpu, network, plugin, etc.
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);
            if (result > 0)
            {
                return(result);
            }
#endif

            var cacheDirBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "cache");
            var settings     = new CefSettings()
            {
                //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                CachePath = cacheDirBase
            };

#if NETCOREAPP
            //We use our Applications exe as the BrowserSubProcess, multiple copies
            //will be spawned
            var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            settings.BrowserSubprocessPath = exePath;
#endif

            //Example of setting a command line argument
            //Enables WebRTC
            // - CEF Doesn't currently support permissions on a per browser basis see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access
            // - CEF Doesn't currently support displaying a UI for media access permissions
            //
            //NOTE: WebRTC Device Id's aren't persisted as they are in Chrome see https://bitbucket.org/chromiumembedded/cef/issues/2064/persist-webrtc-deviceids-across-restart
            settings.CefCommandLineArgs.Add("enable-media-stream");
            //https://peter.sh/experiments/chromium-command-line-switches/#use-fake-ui-for-media-stream
            settings.CefCommandLineArgs.Add("use-fake-ui-for-media-stream");
            //For screen sharing add (see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access#comment-58677180)
            settings.CefCommandLineArgs.Add("enable-usermedia-screen-capturing");
            settings.CefCommandLineArgs.Add("disable-application-cache", "1");

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            var browser = new BrowserForm();

            Application.Run(browser);

            return(0);
        }
Пример #3
0
        public static int Main(string[] args)
        {
            //For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

#if NETCOREAPP
            //We are using our current exe as the BrowserSubProcess
            //Multiple instances will be spawned to handle all the
            //Chromium proceses, render, gpu, network, plugin, etc.
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);
            if (result > 0)
            {
                return(result);
            }
#endif

            var settings = new CefSettings()
            {
                //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
            };

#if NETCOREAPP
            //We use our Applications exe as the BrowserSubProcess, multiple copies
            //will be spawned
            var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            settings.BrowserSubprocessPath = exePath;
#endif

            //Example of setting a command line argument
            //Enables WebRTC
            settings.CefCommandLineArgs.Add("enable-media-stream", "1");

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            // Holds debug information.
            Directory.CreateDirectory(OptionsForm.DataDirectory);

            var browser = new BrowserForm();
            Application.Run(browser);

            return(0);
        }
Пример #4
0
        public static int Main(string[] args)
        {
            // For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

            // We are using our current exe as the BrowserSubProcess
            // Multiple instances will be spawned to handle all the
            // Chromium processes, render, gpu, network, plugin, etc.
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);

            if (result > 0)
            {
                return(result);
            }

            var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            var settings = new CefSettings()
            {
                //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
            };

            // We use our Applications exe as the BrowserSubProcess, multiple copies
            // will be spawned
            var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

            settings.BrowserSubprocessPath = exePath;

            // Specify the standard user data path, to reuse login cookies etc.
            settings.UserDataPath = @$ "{localAppData}\Google\Chrome\User Data";

            // Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            var applicationUrl = args.Length > 0 ? args[0] : BrowserForm.DefaultApplicationUrl;
            var browser        = new BrowserForm(applicationUrl);

            Application.Run(browser);

            return(0);
        }
        public static int Main(string[] args)
        {
            //For Windows 7 and above, app.manifest entries will take precedences of this call
            Cef.EnableHighDPISupport();

            //We are using our current exe as the BrowserSubProcess
            //Multiple instances will be spawned to handle all the
            //Chromium proceses, render, gpu, network, plugin, etc.
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);

            if (result > 0)
            {
                return(result);
            }

            //We use our current exe as the BrowserSubProcess
            var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

            var settings = new CefSettings()
            {
                //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                CachePath             = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
                BrowserSubprocessPath = exePath
            };

            //Example of setting a command line argument
            //Enables WebRTC
            settings.CefCommandLineArgs.Add("enable-media-stream");

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            var app = new App();

            app.InitializeComponent();
            return(app.Run());
        }
Пример #6
0
        public static int Main(string[] args)
        {
            //For Windows 7 and above, app.manifest entries will take precedences of this call
            Cef.EnableHighDPISupport();

            //We are using our current exe as the BrowserSubProcess
            //Multiple instances will be spawned to handle all the
            //Chromium proceses, render, gpu, network, plugin, etc.
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);

            if (result > 0)
            {
                return(result);
            }

            //We use our current exe as the BrowserSubProcess
            //var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            var settings = new CefSettings()
            {
                CachePath             = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Cache"),
                PersistSessionCookies = true,//VERY IMPORTANT
            };
            var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

            settings.BrowserSubprocessPath = exePath;
            //settings.CefCommandLineArgs.Add("enable-media-stream");
            settings.CefCommandLineArgs.Add("no-proxy-server");
            settings.CefCommandLineArgs.Add("proxy-auto-detect", "0");

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
            Cef.EnableHighDPISupport();
            var app = new App();

            app.InitializeComponent();
            return(app.Run());
        }
Пример #7
0
        public static int Main(string[] args)
        {
            //For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

#if NETCOREAPP
            //We are using our current exe as the BrowserSubProcess
            //Multiple instances will be spawned to handle all the
            //Chromium proceses, render, gpu, network, plugin, etc.
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);
            if (result > 0)
            {
                return(result);
            }
#endif

            var settings = new CefSettings()
            {
                //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
            };

#if NETCOREAPP
            //We use our Applications exe as the BrowserSubProcess, multiple copies
            //will be spawned
            var exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            settings.BrowserSubprocessPath = exePath;
#endif
            settings.CefCommandLineArgs.Add("enable-media-stream");
            var    mngr = Cef.GetGlobalCookieManager();
            Cookie Ac   = new Cookie();
            Ac.Name  = "SameSite";
            Ac.Value = "None; Secure";

            Del endFunctionDelegate = new Del(EndFunction);
            var website             = CredentialProvider.GetSiteUrl();

            if (website != null)
            {
                if (website.Equals("https://suplementy.pl/"))
                {
                    browser = new BrowserForm(endFunctionDelegate, settings, new SuplementyService());
                }
                else if (website.Equals("https://www.mpcforum.pl/login"))
                {
                    browser = new BrowserForm(endFunctionDelegate, settings, new MpcForumService());
                }
                else
                {
                    throw new Exception("Website is not supported");
                }
            }
            else
            {
                throw new Exception("Url of website not found");
            }


            int firstRunHour   = 10;
            int firstRunMinute = 10;
            Scheduler.IntervalInDays(firstRunHour, firstRunMinute, 1, () => {
                Application.Run(browser);
            });
            Console.ReadLine();



            return(0);
        }
Пример #8
0
        public static async Task <int> Main(params string[] args)
        {
#if NETCOREAPP
            var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
            var result        = subProcessExe.Main(args);
            if (result > 0)
            {
                return(result);
            }
#endif
            var sourceArgument = new Argument <string>(
                "sourceUrl",
                "URL of the page to capture");

            var windowSizeOption = new Option <Size>(
                new[] { "--window_size", "-ws" },
                "Capture window size specified as width,height without spaces! (e.g. 800,600).")
            {
                Name = "windowSize"
            };

            var viewportOriginOption = new Option <Point>(
                new[] { "--viewport_origin", "-vo" },
                "Viewport origin specified as left,top coordinate without spaces! (e.g. 10,20). Origin is (0, 0) when left unspecified.")
            {
                Name = "viewportOrigin"
            };

            var viewportSizeOption = new Option <Size>(
                new[] { "--viewport_size", "-vs" },
                "Viewport size specified as width,height without spaces! (e.g. 800,600). Captures area below and to the right of the viewport origin when left unspecified.")
            {
                Name = "viewportSize"
            };

            var scaleFactorOption = new Option <decimal>(
                new[] { "--scale_factor", "-sf" },
                () => HtmlSource.DefaultScalingFactor,
                $"Scale factor applied to HTML content.")
            {
                Name = "scaleFactor"
            };

            var frameFormatOption = new Option <FrameFormat>(
                new[] { "--format", "-f" },
                () => FrameFormat.Rgba,
                $"Image format for output frames. Default is {FrameFormat.Rgba}.")
            {
                Name = "frameFormat"
            };

            var chromaColorOption = new Option <string>(
                new[] { "--chromakey-color", "-c" },
                "Pixels with the specified HTML color value are mapped as transparent (e.g. #00FF00, green).")
            {
                Name = "chromaHtmlColor"
            };

            chromaColorOption.Argument.AddValidator(
                arg => {
                var colorValue = arg.GetValueOrDefault <string>();
                return(!colorValue.IsValidHtmlColor() ? $"ERROR: Chroma color value '{colorValue}' has an invalid format." : null);
            });

            var backgroundColorOption = new Option <string>(
                new[] { "--background-color", "-b" },
                "Replaces the background color of the captured page (e.g. #00FF00, green).")
            {
                Name = "backgroundHtmlColor"
            };

            backgroundColorOption.Argument.AddValidator(
                arg => {
                var colorValue = arg.GetValueOrDefault <string>();
                return(!colorValue.IsValidHtmlColor() ? $"ERROR: Background color value '{colorValue}' has an invalid format." : null);
            });

            var traceLevelOption = new Option <TraceLevel>(
                new[] { "--log", "-l" },
                () => TraceLevel.Info,
                $"Console logging level.")
            {
                Name = "traceLevel"
            };

            var quietModeOption = new Option <bool>(
                new[] { "--quiet", "-q" },
                $"Hide banner and input options.")
            {
                Name = "quietMode"
            };

            var rootCommand = new RootCommand()
            {
                sourceArgument,
                windowSizeOption,
                viewportSizeOption,
                viewportOriginOption,
                frameFormatOption,
                chromaColorOption,
                backgroundColorOption,
                scaleFactorOption,
                traceLevelOption,
                quietModeOption
            };

            rootCommand.Description =
                @"HTML Video Source

- Captures output from a Web page as a sequence of images to be used as a video source.
";
            rootCommand.Handler = CommandHandler.Create((RunHandler)Run);

            result = await rootCommand.InvokeAsync(args);

            return(result);
        }