Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Loading HTML

[email protected] edited this page Nov 29, 2019 · 1 revision

In the following code snippets, the HTML file is stored under app/chromely.html. It's not required to be under app/. Feel free to create your file structure as you see fit, this is just an example.

A real website URL

This will launch actual website URL. This may not necessarily be commonly used as Chromely is focused on loading local HTML5 files for Single Page Applications. This URL should also be of scheme and domain combination that is not registered as external URL scheme. For external URL scheme registration, please see.

class Program
{
   static int Main(string[] args)
   {
      string startUrl = "https://google.com";

      //...
  }
}

JavaScript Framework

For more information please visit Chromely Apps.

Local Resource Loading

This is the preferred way of loading local HTML5 files.

You can either:

  • Use the default local resource scheme handling or create a custom one. (Please see samples - CefSharp, CefGlue)
  • Use the default scheme handler or registering a new one.

Setting up the ResourceSchemeHandler

class Program
{
   static int Main(string[] args)
   {
      string startUrl = "local://app/chromely.html";

      var config = ChromelyConfiguration
                        .Create()
                        //...
                        .UseDefaultResourceSchemeHandler("local", string.Empty);
                        //Or register new resource handler
                        //RegisterSchemeHandler("local", string.Empty,  new CustomResourceHandler())

      //...
  }
}

Setting up the HttpSchemeHandler

class Program
{
   static int Main(string[] args)
   {
      string startUrl = "local://app/chromely.html";

      var config = ChromelyConfiguration
                        .Create()
                        //...
                        .UseDefaultHttpSchemeHandler("http", "chromely.com")
                        //Or register new http scheme handler
                        //RegisterSchemeHandler("http", "example.com",  new CustomHttpHandler())

      //...
  }
}

File Protocol

Local HTML5 files can also be loaded using file protocol (file:///). Using file protocol (file:///) is discouraged for security reasons. One issue might be Cross-Origin domain. Although not the preferred way, it is useful if HTML/Ajax XHR requests are required.

You can either:

  • Use the default local resource scheme handling or create a custom one. (Please see samples - CefSharp, CefGlue)
  • Use the default scheme handler or registering a new one.

Setting up the ResourceSchemeHandler

class Program
{
   static int Main(string[] args)
   {
      var appDirectory = AppDomain.CurrentDomain.BaseDirectory;
      string startUrl = $"file:///{appDirectory}app/chromely.html";

      var config = ChromelyConfiguration
                        .Create()
                        //...
                        .UseDefaultResourceSchemeHandler("local", string.Empty);
                        //Or register new resource handler
                        //RegisterSchemeHandler("local", string.Empty,  new CustomResourceHandler())

      //...
  }
}

Setting up the HttpSchemeHandler

class Program
{
   static int Main(string[] args)
   {
      var appDirectory = AppDomain.CurrentDomain.BaseDirectory;
      string startUrl = $"file:///{appDirectory}app/chromely.html";

      var config = ChromelyConfiguration
                        .Create()
                        //...
                        .UseDefaultHttpSchemeHandler("http", "chromely.com")
                        //Or register new http scheme handler
                        //RegisterSchemeHandler("http", "example.com",  new CustomHttpHandler())

      //...
  }
}
Clone this wiki locally