1

I got the following code

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 file contains

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"
};

The window and the window.screen are working , but I can't manage to override window.navigator. I have found window.navigator object on mozilla dev. but for some strange reason , my solution does not work. What I try to do , is to modify window.navigator properties and to add plugins. Any ideas on how to do that ?

Stoica Nicusor
  • 211
  • 4
  • 9

1 Answers1

0

The 'window.navigator' property is read-only, so you cannot update its value. However, if you need to change the user-agent string in DotNetBrowser, you can do this using the following approach:

Browser browser = BrowserFactory.Create(); browser.UserAgent = "Modified User Agent String";

You can find information related to the user-agent string in the following article: https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110164-user-agent

Eugene Yakush
  • 259
  • 4
  • 6