protected void OnInitialized() { var switches = DotNetBrowserSwitches.Create(BrowserType); BrowserPreferences.SetChromiumSwitches(switches.ToArray()); _path = GetOrCreateContextParamsPath(); _browserContext = new BrowserContext(new BrowserContextParams(_path)); browser = BrowserFactory.Create(_browserContext, BrowserType); browser.Preferences.AllowDisplayingInsecureContent = false; browser.Preferences.AllowRunningInsecureContent = false; browser.Preferences.AllowScriptsToCloseWindows = false; browser.Preferences.ApplicationCacheEnabled = false; browser.Preferences.DatabasesEnabled = false; browser.Preferences.LocalStorageEnabled = false; browser.Preferences.PluginsEnabled = false; browser.Preferences.TransparentBackground = true; browser.Preferences.UnifiedTextcheckerEnabled = false; browser.Preferences.WebAudioEnabled = false; browser.ZoomEnabled = true; browser.DialogHandler = this; browser.LoadHandler = this; browser.Context.NetworkService.ResourceHandler = this; browser.RenderGoneEvent += Browser_RenderGoneEvent; browser.ScriptContextCreated += Browser_ScriptContextCreated; }
public TabControlSystem(Panel containerForTabSystem) { this.containerForTabSystem = containerForTabSystem; this.tabList = new List <Tab>(); this.createUI(); BrowserPreferences.SetChromiumSwitches("--enable-npapi"); }
static void Main(string[] args) { int viewWidth = 1024; int viewHeight = 20000; string[] switches = { "--disable-gpu", "--max-texture-size=" + viewHeight }; BrowserPreferences.SetChromiumSwitches(switches); Browser browser = BrowserFactory.Create(BrowserType.LIGHTWEIGHT); browser.SetSize(viewWidth, viewWidth); ManualResetEvent waitEvent = new ManualResetEvent(false); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { // Wait until main document of the web page is loaded completely. if (e.IsMainFrame) { waitEvent.Set(); } }; browser.LoadURL("teamdev.com/dotnetbrowser"); waitEvent.WaitOne(); // #3 Set the required document size. JSValue documentHeight = browser.ExecuteJavaScriptAndReturnValue( "Math.max(document.body.scrollHeight, " + "document.documentElement.scrollHeight, document.body.offsetHeight, " + "document.documentElement.offsetHeight, document.body.clientHeight, " + "document.documentElement.clientHeight);"); JSValue documentWidth = browser.ExecuteJavaScriptAndReturnValue( "Math.max(document.body.scrollWidth, " + "document.documentElement.scrollWidth, document.body.offsetWidth, " + "document.documentElement.offsetWidth, document.body.clientWidth, " + "document.documentElement.clientWidth);"); int scrollBarSize = 25; viewWidth = (int)documentWidth.GetNumber() + scrollBarSize; viewHeight = (int)documentHeight.GetNumber() + scrollBarSize; Debug.WriteLine("GetImage: {0} x {1}", viewWidth, viewHeight); Image img = browser.ImageProvider.GetImage(viewWidth, viewHeight); img.Save(@"teamdev.png", System.Drawing.Imaging.ImageFormat.Png); browser.Dispose(); }
public MainWindow() { BrowserPreferences.SetUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"); InitializeComponent(); browser = BrowserFactory.Create(); browserView = new WPFBrowserView(browser); mainLayout.Children.Add(browserView); browser.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"; browserView.Browser.LoadURL("kirksey.helpdocsonline.com"); }
public MainForm() { SetProcessDPIAware(); InitializeComponent(); WinFormsUIContext.Instance.Value = WindowsFormsSynchronizationContext.Current; InitializeComponent(); String[] arguments = Environment.GetCommandLineArgs(); System.Collections.Generic.List <string> switches = new System.Collections.Generic.List <string>(); foreach (string arg in arguments) { if (arg != null && arg.ToLower().Contains("enable-file-log")) { LoggerProvider.Instance.LoggingEnabled = true; LoggerProvider.Instance.FileLoggingEnabled = true; Guid guid = Guid.NewGuid(); string logFile = String.Format("DotNetBrowser-WinForms-{0}.log", guid); LoggerProvider.Instance.OutputFile = System.IO.Path.GetFullPath(logFile); } if (arg != null && arg.ToLower().Contains("lightweight")) { TabFactory.BrowserType = BrowserType.LIGHTWEIGHT; } if (arg != null && arg.ToLower().Contains("npapi")) { switches.Add("--enable-npapi"); } if (arg != null && arg.StartsWith("--remote-debugging-port=")) { switches.Add(arg); } if (arg != null && arg.ToLower().Contains("silent-download")) { DefaultDownloadHandler.DownloadMode = DownloadMode.Silent; } } if (switches.Count > 0) { BrowserPreferences.SetChromiumSwitches(switches.ToArray()); } tabbedPane = new TabbedPane(); InsertTab(TabFactory.CreateFirstTab()); InsertNewTabButton(); this.Controls.Add(tabbedPane); Application.ApplicationExit += delegate { tabbedPane.DisposeAllTabs(); }; }
protected void OnInitialized() { var switches = DotNetBrowserSwitches.Create(BrowserType); BrowserPreferences.SetChromiumSwitches(switches.ToArray()); _path = GetOrCreateContextParamsPath(); _browserContext = new BrowserContext(new BrowserContextParams(_path)); var browser = BrowserFactory.Create(_browserContext, BrowserType); browser.Preferences.AllowDisplayingInsecureContent = false; browser.Preferences.AllowRunningInsecureContent = false; browser.Preferences.AllowScriptsToCloseWindows = false; browser.Preferences.ApplicationCacheEnabled = false; browser.Preferences.DatabasesEnabled = false; browser.Preferences.LocalStorageEnabled = false; browser.Preferences.PluginsEnabled = false; browser.Preferences.TransparentBackground = true; browser.Preferences.UnifiedTextcheckerEnabled = false; browser.Preferences.WebAudioEnabled = false; browser.ZoomEnabled = true; browser.DialogHandler = this; browser.LoadHandler = this; browser.Context.NetworkService.ResourceHandler = this; browser.RenderGoneEvent += Browser_RenderGoneEvent; browser.ScriptContextCreated += Browser_ScriptContextCreated; _browserView = new WPFBrowserView(browser); browser.ConsoleMessageEvent += Browser_ConsoleMessageEvent; _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut1Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D1))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut2Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D2))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut3Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D3))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut4Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D4))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut5Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D5))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut6Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D6))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut7Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D7))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut8Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D8))); _browserView.InputBindings.Add(new InputBinding(new BookmarkShortcut9Command(), new KeyChordGesture(ModifierKeys.Shift | ModifierKeys.Control, Key.OemQuestion, Key.D9))); #if DEBUG Log.Debug(GetDevToolsUrl()); #endif }
public DockPanel(ExternalEvent exEvent, RequestHandler handler) { LoggerProvider.Instance.LoggingEnabled = true; LoggerProvider.Instance.FileLoggingEnabled = true; LoggerProvider.Instance.OutputFile = "H:/DotNetBrowser.log"; BrowserPreferences.SetUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"); BrowserPreferences.SetChromiumSwitches("--lang=en"); InitializeComponent(); m_ExEvent = exEvent; m_Handler = handler; //setupBrowser(); browserView.Browser.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"; browserView.Browser.LoadURL("https://kirksey.helpdocsonline.com"); //mainLayout.Children.Add((UIElement)webView.GetComponent()); //webView.Browser.UserAgent = "Mozilla / 5.0(iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit / 603.1.30(KHTML, like Gecko) Version / 10.0 Mobile / 14E304 Safari / 602.1"; //webView.Browser.LoadURL("https://kirksey.helpdocsonline.com"); }
public MainWindow() { BrowserPreferences.SetChromiumSwitches("--force-renderer-accessibility"); InitializeComponent(); }
public Window() { int viewHeight = 20000; // Disables GPU process and changes maximum texture size // value from default 16384 to viewHeight. The maximum texture size value // indicates the maximum height of the canvas where Chromium // renders web page's content. If the web page's height // exceeds the maximum texture size, the part of outsize the // texture size will not be drawn and will be filled with // black color. String[] switches = { "--disable-gpu", "--disable-gpu-compositing", "--max-texture-size=" + viewHeight }; BrowserPreferences.SetChromiumSwitches(switches); // #1 Create LIGHTWEIGHT Browser instance. browserView = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.LIGHTWEIGHT)); AutoSize = true; AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; // Controls.Add(browserView); this.Load += delegate { Browser browser = browserView.Browser; // #1 Set browser initial size browserView.Browser.SetSize(1280, 1024); // #2 Load web page and wait until web page is loaded completely. ManualResetEvent resetEvent = new ManualResetEvent(false); FinishLoadingFrameHandler listener = new FinishLoadingFrameHandler((object sender, FinishLoadingEventArgs e) => { if (e.IsMainFrame) { resetEvent.Set(); } }); browser.FinishLoadingFrameEvent += listener; try { browser.LoadURL("teamdev.com/dotnetbrowser"); resetEvent.WaitOne(new TimeSpan(0, 0, 45)); } finally { browser.FinishLoadingFrameEvent -= listener; } // #3 Set the required document size. JSValue documentHeight = browserView.Browser.ExecuteJavaScriptAndReturnValue( "Math.max(document.body.scrollHeight, " + "document.documentElement.scrollHeight, document.body.offsetHeight, " + "document.documentElement.offsetHeight, document.body.clientHeight, " + "document.documentElement.clientHeight);"); JSValue documentWidth = browserView.Browser.ExecuteJavaScriptAndReturnValue( "Math.max(document.body.scrollWidth, " + "document.documentElement.scrollWidth, document.body.offsetWidth, " + "document.documentElement.offsetWidth, document.body.clientWidth, " + "document.documentElement.clientWidth);"); int scrollBarSize = 25; int viewWidth = (int)documentWidth.GetNumber() + scrollBarSize; viewHeight = (int)documentHeight.GetNumber() + scrollBarSize; var viewSize = new Size(viewWidth, viewHeight); // #4 Register OnRedraw to get notifications // about paint events. We expect that web page will be completely rendered twice: // 1. When its size is updated. // 2. When HTML content is loaded and displayed. ManualResetEvent waitEvent = new ManualResetEvent(false); DrawingView drawingView = (DrawingView)browserView.GetInnerView(); drawingView.OnRedraw += delegate(object sender, OnRedrawEventArgs e) { // Make sure that all view content has been repainted. if (e.UpdatedRect.Size.Equals(viewSize)) { // #6 Save Image of the loaded web page into a PNG file. browserView.GetImage().Save(@"teamdev.png", ImageFormat.Png); DialogResult = DialogResult.Cancel; } }; browserView.Browser.SetSize(viewWidth, viewHeight); }; }