Update
Added a request handler. Changed the way you block sites. Disabled GPU acceleration and GPU vsync. Enabled webgl. Removed the rick roll blocking because I see it pointless.
This commit is contained in:
parent
7d6b3b5144
commit
f03e0e3bf5
4 changed files with 162 additions and 248 deletions
|
@ -1,64 +1,94 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Bunifu.UI.WinForms;
|
||||
using CefSharp;
|
||||
using CefSharp.WinForms;
|
||||
|
||||
|
||||
namespace XeroBrowser
|
||||
{
|
||||
public class RequestHandler : IRequestHandler
|
||||
public class RequestHandler : CefSharp.Handler.RequestHandler
|
||||
{
|
||||
public bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
|
||||
|
||||
// Define arrays with domain names only
|
||||
private readonly string[] blockedDrms = { "netflix.com", "www.netflix.com", "disneyplus.com", "twitch.tv", "tiktok.com" };
|
||||
private readonly string[] incompatibleExtSites = { "chrome.google.com", "addons.mozilla.org", "chromewebstore.google.com" };
|
||||
private string[] adDomains;
|
||||
|
||||
public RequestHandler()
|
||||
{
|
||||
// Fetch the blocked domains asynchronously when the RequestHandler is instantiated
|
||||
FetchAdDomainsAsync().ContinueWith(t => adDomains = t.Result);
|
||||
}
|
||||
|
||||
public async Task<string[]> FetchAdDomainsAsync()
|
||||
{
|
||||
string[] adDomains = Array.Empty<string>();
|
||||
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
string url = "https://diamondcreeper.org/web-filtering/lists/ads.txt";
|
||||
HttpResponseMessage response = await client.GetAsync(url);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
string[] adsDomains = content.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error fetching ad domains: {ex.Message}");
|
||||
}
|
||||
|
||||
return adDomains;
|
||||
}
|
||||
|
||||
protected override bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
|
||||
protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
|
||||
protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
Uri requestUri = new Uri(request.Url);
|
||||
string domain = requestUri.Host.ToLower();
|
||||
|
||||
public bool OnCertificateError(IWebBrowser chromiumWebBrowser, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
if (blockedDrms.Contains(domain))
|
||||
{
|
||||
// Cancel the navigation or sub-request
|
||||
chromiumWebBrowser.LoadHtml("<html> <head> </head> <style> body{ background-color: rgb(214, 214, 214); } .center{ text-align: center; } .text{ margin-top: 20%; font-family: Arial; } div{ background-color: #f5f5f5; border-radius: 15px; width: 500px; margin-left: 35%; padding: 10px; } </style> <body class=\"center\"> <div class=\"text\"> <h1>Error!</h1> <h3>The requested site requires a DRM (Digital Rights Management) which Xero Browser does not support!</h3> </div> </body></html>");
|
||||
|
||||
public void OnDocumentAvailableInMainFrame(IWebBrowser chromiumWebBrowser, IBrowser browser)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
// Clear the txtSearchOrUrl text box
|
||||
//txtSearchOrUrl.Text = string.Empty;
|
||||
}
|
||||
else if (incompatibleExtSites.Contains(domain))
|
||||
{
|
||||
// Cancel the navigation or sub-request
|
||||
chromiumWebBrowser.LoadHtml("<html> <head> </head> <style> body{ background-color: rgb(214, 214, 214); } .center{ text-align: center; } .text{ margin-top: 20%; font-family: Arial; } div{ background-color: #f5f5f5; border-radius: 15px; width: 500px; margin-left: 35%; padding: 10px; } </style> <body class=\"center\"> <div class=\"text\"> <h1>Error!</h1> <h3>Browser extensions are not supported!</h3> </div> </body></html>");
|
||||
|
||||
public bool OnOpenUrlFromTab(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
// Clear the txtSearchOrUrl text box
|
||||
//txtSearchOrUrl.Text = string.Empty;
|
||||
}
|
||||
else if (adDomains.Contains(domain))
|
||||
{
|
||||
chromiumWebBrowser.LoadHtml("<html> <head> </head> <style> body{ background-color: rgb(214, 214, 214); } .center{ text-align: center; } .text{ margin-top: 20%; font-family: Arial; } div{ background-color: #f5f5f5; border-radius: 15px; width: 500px; margin-left: 35%; padding: 10px; } </style> <body class=\"center\"> <div class=\"text\"> <h1>Ads are blocked!</h1> <h3>Ads are blocked in xero browser</h3> </div> </body></html>");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnPluginCrashed(IWebBrowser chromiumWebBrowser, IBrowser browser, string pluginPath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool OnQuotaRequest(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, long newSize, IRequestCallback callback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void OnRenderProcessTerminated(IWebBrowser chromiumWebBrowser, IBrowser browser, CefTerminationStatus status)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void OnRenderViewReady(IWebBrowser chromiumWebBrowser, IBrowser browser)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool OnSelectClientCertificate(IWebBrowser chromiumWebBrowser, IBrowser browser, bool isProxy, string host, int port, X509Certificate2Collection certificates, ISelectClientCertificateCallback callback)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue