title: CefSharp: Injecting custom CSS File using a custom scheme
body: <p>I'm using CefSharp (47) to render a webpage from a host that I have no control over, and I want to make some additional CSS tweaks to those provided by the host.</p>
  
  <p>Reading up on various topics across GitHub (<a href="https://github.com/cefsharp/CefSharp/blob/cefsharp/47/CefSharp.Example/CefSharpSchemeHandlerFactory.cs" rel="nofollow noreferrer">https://github.com/cefsharp/CefSharp/blob/cefsharp/47/CefSharp.Example/CefSharpSchemeHandlerFactory.cs</a>), and here (<a href="https://stackoverflow.com/questions/35965912/cefsharp-custom-schemehandler">CefSharp custom SchemeHandler</a>), I wrote a custom scheme handler accordingly:</p>
  
  <pre><code>public class CustomSchemeHandlerFactory : ISchemeHandlerFactory
  {
      public const string SchemeName = "custom";
  
      public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
      {
          Console.WriteLine(request.Url);
  
          if (schemeName.ToLower() == SchemeName.ToLower())
          {
              // Do some stuff
          }
          return null;
      }
  }
  </code></pre>
  
  <p>I attempt to bind it in my application in the following manner:</p>
  
  <pre><code>            CefSettings settings = new CefSettings();
              settings.CachePath = browserCachePath;
              settings.RegisterScheme(new CefCustomScheme()
              {
                  SchemeName = CustomSchemeHandlerFactory.SchemeName,
                  SchemeHandlerFactory = new CustomSchemeHandlerFactory()
              });
              Cef.Initialize(settings);
  </code></pre>
  
  <p>The application then browses to the appropriate website, and uses the 'LoadingStateChanged' event to then fire off some JavaScript to inject the CSS file I want to load:</p>
  
  <pre><code>        string linkText = "&lt;link rel=\u0022stylesheet\u0022 type=\u0022text/css\u0022 href=\u0022custom://custom.css\u0022&gt;";
          var jsFunctionText = string.Format("(function() {{ $('head').append('{0}'); return true;}}) ();", linkText);
  
          var injectionTask = await _myBrowser.GetMainFrame().EvaluateScriptAsync(jsFunctionText, null);
  </code></pre>
  
  <p>...which succeeds.</p>
  
  <p>But my custom resource handler 'Create' event is never fired.</p>
  
  <p>I can only presume that the handler isn't being registered properly, so I'd appreciate any advice/help in getting this working properly!</p>
  
  <p>Thanks!</p>