HTML5 supports Web Storage API that allows browsers to store key/value pairs, in a much more better way than using cookies. Web Storage API provides two mechanisms of storing data locally:

  • window.localStorage stores data with no expiration date.
  • window.sessionStorage> stores data for one session (data is lost when the browser tab is closed).

DotNetBrowser provides API that allows working with both Local and Session storages:

  • Browser.GetLocalWebStorage() returns Local web storage instance.
  • Browser.GetSessionWebStorage() returns Session web storage instance. Local and Session storages implement same IWebStorage interface that provides methods for working with storage.

The following sample demonstrates how to access Local web storage of the loaded web page, read and set key/value pairs:

using DotNetBrowser;
using DotNetBrowser.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace WebStorageSample
    /// <summary>
    /// The sample demonstrates how to access WebStorage on
    /// the loaded web page using DotNetBrowser API.
    /// </summary>
    class Program
       public class WindowMain : Window
           private WPFBrowserView browserView;
           public WindowMain()
               BrowserContext browserContext = BrowserContext.DefaultContext;
               Browser browser = BrowserFactory.Create(browserContext);
               browser.DocumentLoadedInMainFrameEvent += delegate
                   IWebStorage webStorage = browser.GetLocalWebStorage();
                   // Read and display the 'myKey' storage value.
                   Console.Out.WriteLine("The myKey value: " + webStorage["myKey"]);
                   // Modify the 'myKey' storage value.
                   webStorage.Set("myKey", "Hello from Local Storage");
               browserView = new WPFBrowserView(browser);
               Content = browserView;
               Width = 1024;
               Height = 768;
               this.Loaded += WindowMain_Loaded;
           void WindowMain_Loaded(object sender, RoutedEventArgs e)
               browserView.Browser.LoadHTML(new LoadHTMLParams(
                      "<html><body><button onclick=\"myFunction()\">Modify 'myKey' value</button>" +
                              "<script>localStorage.myKey = \"Initial Value\";" +
                              "function myFunction(){alert(localStorage.myKey);}" +
           public static void Main()
               Application app = new Application();
               WindowMain wnd = new WindowMain();
               var browser = wnd.browserView.Browser;