다음 코드는DotNetBrowser는 재정의 window.navigator
using DotNetBrowser;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Browsium
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Browser browser;
private DotNetBrowser.WinForms.WinFormsBrowserView bview;
private void Form1_Load(object sender, EventArgs e)
{
browser = BrowserFactory.Create(BrowserContext.DefaultContext,BrowserType.HEAVYWEIGHT);
browser.ScriptContextCreated += Browser_ScriptContextCreated;
bview = new DotNetBrowser.WinForms.WinFormsBrowserView(browser);
this.Controls.Add(bview);
browser.LoadURL("https://whoer.net/#extended");
}
private void Browser_ScriptContextCreated(object sender, DotNetBrowser.Events.ScriptContextEventArgs e)
{
// demo
browser.ExecuteJavaScriptAndReturnValue(e.Context.FrameId, System.IO.File.ReadAllText("test.js"));
}
}
}
test.js 파일은
window = new function() {
this.innerWidth = 240,
this.innerHeight = 182
};
window.screen = new function() {
this.availHeight = 320,
this.availLeft = 0,
this.availTop = 0,
this.availWidth = 240,
this.clientHeight = 320,
this.clientWidth = 240,
this.colorDepth = 24,
this.height = 320,
this.left = 0,
this.offsetHeight = 320,
this.offsetWidth = 240,
this.pixelDepth = 24,
this.top = 0,
this.width = 240,
this.orientation = "landscape-primary",
this.mozEnabled = true
};
window.navigator = new function() {
this.userAgent = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.70 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.70",
this.appCodeName = "Mozilla",
this.appName = "Netscape",
this.appVersion = "5.0 (Windows NT 10.0) AppleWebKit/537.70 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.70",
this.language = "en",
this.languages = "en",
this.platform = "x86",
this.oscpu = "x86",
this.hardwareConcurrency = "8",
this.vendor = "Test Inc.",
this.vendorSub = "",
this.buildID = "",
this.product = "Chrome",
this.productSub = "20030107"
};
창 및 작업중인 window.screen이 포함되어있어,하지만 난 무시할 관리 할 수 없습니다 window.navigator. mozilla dev에 window.navigator 객체가 있습니다. 하지만 몇 가지 이상한 이유로, 내 솔루션이 작동하지 않습니다. 내가하려는 것은 window.navigator 속성을 수정하고 플러그인을 추가하는 것입니다. 그 방법에 대한 아이디어가 있습니까?