Ejemplo n.º 1
0
        private void Browser_FrameLoadStart(object sender, FrameLoadStartEventArgs e)
        {
            if (!e.Frame.IsMain)
            {
                return;
            }

            lastUrl = e.Url;

            if (_api != null)
            {
                var initScript = @"(async () => {
                    await CefSharp.BindObjectAsync('OverlayPluginApi');
                    OverlayPluginApi.overlayName = " + JsonConvert.SerializeObject(this.overlayName) + @";
                    OverlayPluginApi.overlayUuid = " + JsonConvert.SerializeObject(this.overlayUuid) + @";
                    OverlayPluginApi.ready = true;
                })();";
                e.Frame.ExecuteJavaScriptAsync(initScript, "init");
            }

            foreach (var item in this.scriptQueue)
            {
                e.Frame.ExecuteJavaScriptAsync(item, "injectOnLoad");
            }
            this.scriptQueue.Clear();

            try
            {
                BrowserStartLoading?.Invoke(this, new BrowserLoadEventArgs(0, e.Url));
            } catch (Exception ex)
            {
                BrowserConsoleLog?.Invoke(this, new BrowserConsoleLogEventArgs(ex.ToString(), "", 1));
            }
        }
Ejemplo n.º 2
0
        public async void ClearCache()
        {
            try
            {
                if (_browser == null)
                {
                    return;
                }

                // Find the first / after https://
                var slashAfterHost = lastUrl.IndexOf("/", 9);

                // If we can't build an origin, there's nothing we can do.
                if (slashAfterHost < 0)
                {
                    return;
                }

                var origin = lastUrl.Substring(0, slashAfterHost);
                var dtc    = DevToolsExtensions.GetDevToolsClient(_browser);
                var result = await dtc.Storage.ClearDataForOriginAsync(origin, "appcache,cookies,file_systems,cache_storage");

                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs(result.Success ? result.ResponseAsJsonString : "fail", "", 0));

                // Reload the overlay to refill the cache and replace that potentially corrupted resources.
                Reload();
            }
            catch (Exception ex)
            {
                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs($"Failed to clear cache: {ex}", "", 0));
            }
        }
Ejemplo n.º 3
0
 public void Browser_ConsoleMessage(object sender, ConsoleMessageEventArgs e)
 {
     // Ignore FLoC exception errors. CEF doesn't include FLoC code which means that it doesn't understand
     // the FLoC exception rule. However, since it can't use FLoC to begin with, that's not an issue either way.
     if (!e.Message.StartsWith("Error with Permissions-Policy header:"))
     {
         BrowserConsoleLog?.Invoke(sender, new BrowserConsoleLogEventArgs(e.Message, e.Source, e.Line));
     }
 }
Ejemplo n.º 4
0
 private void Browser_LoadError(object sender, LoadErrorEventArgs e)
 {
     try
     {
         BrowserError?.Invoke(sender, new BrowserErrorEventArgs(e.ErrorCode, e.ErrorText, e.FailedUrl));
     } catch (Exception ex)
     {
         BrowserConsoleLog?.Invoke(this, new BrowserConsoleLogEventArgs(ex.ToString(), "", 1));
     }
 }
Ejemplo n.º 5
0
        private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
        {
            if (urlToLoad != null)
            {
                _browser.Load(urlToLoad);
                urlToLoad = null;
            }

            try
            {
                BrowserLoad?.Invoke(sender, new BrowserLoadEventArgs(e.HttpStatusCode, e.Url));
            } catch (Exception ex)
            {
                BrowserConsoleLog?.Invoke(this, new BrowserConsoleLogEventArgs(ex.ToString(), "", 1));
            }
        }
Ejemplo n.º 6
0
        public async void ClearCache()
        {
            try
            {
                if (_browser == null || !_isRendering)
                {
                    return;
                }

                var dtc    = DevToolsExtensions.GetDevToolsClient(_browser);
                var result = await dtc.Network.ClearBrowserCacheAsync();

                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs(result.Success ? result.ResponseAsJsonString : "fail", "", 0));
                // Restart the broswer to avoid memory cache, and refill the cache and replace that potentially corrupted resources.
                BeginRender();
            }
            catch (Exception ex)
            {
                BrowserConsoleLog?.Invoke(null, new BrowserConsoleLogEventArgs($"Failed to clear cache: {ex}", "", 0));
            }
        }
Ejemplo n.º 7
0
 internal void OnConsoleLog(CefBrowser browser, string message, string source, int line)
 {
     BrowserConsoleLog?.Invoke(this, new BrowserConsoleLogEventArgs(message, source, line));
 }
Ejemplo n.º 8
0
 public void Browser_ConsoleMessage(object sender, ConsoleMessageEventArgs e)
 {
     BrowserConsoleLog?.Invoke(sender, new BrowserConsoleLogEventArgs(e.Message, e.Source, e.Line));
 }
Ejemplo n.º 9
0
 public void Browser_ConsoleMessage(object sender, BrowserConsoleLogEventArgs e)
 {
     BrowserConsoleLog?.Invoke(sender, e);
 }