DotNetBrowser is based on the Chromium engine. There are lots of command lines (switches) which can be used with Chromium. Some of them change the behavior of features, others are for debugging or experimenting.


DotNetBrowser provides API that allows configuring Chromium with command line switches. You can provide the list of command line switches before you create any Browser instance. The following code demonstrates how to do it:


//these switches allow loading file resources from the file system:
BrowserPreferences.SetChromiumSwitches("--disable-web-security",
    "--allow-file-access-from-files");


All the switches must be specified before creating any BrowserView instance.

 

The following sample demonstrates how to disable web security and allow file access from HTML via appropriate Chromium switches:


MainWindow.xaml

<Window x:Class="ChromiumSwitchesSample.MainWindow"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:wpf="clr-namespace:DotNetBrowser.WPF;assembly=DotNetBrowser"  
Title="MainWindow" Height="350" Width="525" Closing="Window_Closing"> 
     <Grid Name="mainLayout">  
        <wpf:WPFBrowserView Name="browserView" />  
    </Grid> 
</Window>


MainWindow.xaml.cs

using DotNetBrowser;
using DotNetBrowser.WPF;
using System;
using System.Windows;

namespace ChromiumSwitchesSample
{
   /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            BrowserPreferences.SetChromiumSwitches("--disable-web-security",
                "--allow-file-access-from-files");
            InitializeComponent();
            //use the absolute path to files
            browserView.Browser.LoadHTML(
                "<html><body>Image:<img src='file:///C:\\image.jpg'></body></html>");
        }
    }
}

Useful Switches

  • --disable-pinch – disables touch-screen pinch gestures.
  • --disable-gpu – disables GPU hardware acceleration.
  • --overscroll-history-navigation=0 – disables history navigation on horizontal overscroll.
  • --ppapi-flash-path ,--ppapi-flash-version – allows specifying the path to the PPAPI Flash plugin version DLL. Specifying its version is required.
  • --force-renderer-accessibility – forces Chromium accessibility to be enabled at launch. If this flag is specified, the contents of the control running in the heavyweight mode will be available for UI Automation.