wabbajack/Wabbajack.App/Utilities/CefAppImpl.cs

71 lines
2.2 KiB
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
using System.Runtime.InteropServices;
using CefNet;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.App.Utilities;
internal class CefAppImpl : CefNetApplication
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
public Action<long> ScheduleMessagePumpWorkCallback { get; set; }
protected override void OnBeforeCommandLineProcessing(string processType, CefCommandLine commandLine)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
base.OnBeforeCommandLineProcessing(processType, commandLine);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
Console.WriteLine("ChromiumWebBrowser_OnBeforeCommandLineProcessing");
Console.WriteLine(commandLine.CommandLineString);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
//commandLine.AppendSwitchWithValue("proxy-server", "127.0.0.1:8888");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
commandLine.AppendSwitchWithValue("remote-debugging-port", "9222");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
//enable-devtools-experiments
commandLine.AppendSwitch("enable-devtools-experiments");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
//e.CommandLine.AppendSwitchWithValue("user-agent", "Mozilla/5.0 (Windows 10.0) WebKa/" + DateTime.UtcNow.Ticks);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
//("force-device-scale-factor", "1");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
//commandLine.AppendSwitch("disable-gpu");
//commandLine.AppendSwitch("disable-gpu-compositing");
//commandLine.AppendSwitch("disable-gpu-vsync");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
commandLine.AppendSwitch("enable-begin-frame-scheduling");
commandLine.AppendSwitch("enable-media-stream");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
commandLine.AppendSwitchWithValue("enable-blink-features", "CSSPseudoHas");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
commandLine.AppendSwitch("no-zygote");
commandLine.AppendSwitch("no-sandbox");
}
}
protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
{
base.OnContextCreated(browser, frame, context);
frame.ExecuteJavaScript(@"
2021-09-27 12:42:46 +00:00
{
const newProto = navigator.__proto__;
delete newProto.webdriver;
navigator.__proto__ = newProto;
}", frame.Url, 0);
2021-10-23 16:51:17 +00:00
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
protected override void OnCefProcessMessageReceived(CefProcessMessageReceivedEventArgs e)
{
base.OnCefProcessMessageReceived(e);
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
protected override CefRenderProcessHandler GetRenderProcessHandler()
{
return base.GetRenderProcessHandler();
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
protected override void OnScheduleMessagePumpWork(long delayMs)
{
ScheduleMessagePumpWorkCallback(delayMs);
2021-09-27 12:42:46 +00:00
}
}