Welcome Guest Search | Active Topics | Sign In | Register

User Agent Proprerty Not Showing Options
RedCarpet
Posted: Tuesday, April 23, 2024 3:26:29 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2024
Posts: 7
Hello

i set on code this:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Initialize the WebView using the PictureBox's window handle

m_WebView.Create(PictureBox1.Handle)
'Load Google's home page into the WebView
m_WebView.Engine.Options.CustomUserAgent = "123456"
m_WebView.Url = "http://localhost:50122/clienti.aspx"

End Sub

Where localhost is my own web page, in my web page i set this user agent check on page load:
Label1.Text = Request.Headers("User-Agent").ToString()

But instead of get "123456" in label 1 i get usual useragent :
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"


Why i want modificate user agent?

Because i want my website will open only with custom browser EO webbrowser based

Thanks



eo_support
Posted: Wednesday, April 24, 2024 10:42:18 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,133
Hi,

You need to set your user agent BEFORE you create any WebView object.

Thanks!
RedCarpet
Posted: Wednesday, April 24, 2024 3:21:52 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2024
Posts: 7
Thanks a lot

I have done , and it works.

My intent is that my asp website will be navigable only from my custon browser EssentialObject based.

Can you suggest me some way?

I can manage executable code and asp.net code.

I tryed setting a customuseragent property like "4764477" and made a check on asp.net webpages load that display only if detect "4764477" user agent, this way worked but i have a trouble, making this particular "custom" user agent name the page is very bad displayed and almost not usable ( listbox with blank , desized, decentrated etc)

At end i am searching a way to make website navigable only from essential object based custom browser

Thanks A lot for help you are giving as
eo_support
Posted: Wednesday, April 24, 2024 3:33:09 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,133
Hi,

You don't have to replace the entire user agent. You can just add something to it. For example, you can set it to:

Code:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 4764477

This way your website will still think the browser is Chrome and render the correct HTML, but you can still check whether your custom value "4764477" is present in the user agent string.

Another way to do it is add a custom header entry in BeforeRequestLoad event:

https://www.essentialobjects.com/doc/eo.webbrowser.webview.beforerequestload.html

You can then check if the custom header entry is present in your server side code.

Thanks!
KSystems
Posted: Friday, April 26, 2024 4:14:05 PM
Rank: Advanced Member
Groups: Member

Joined: 1/15/2015
Posts: 47
Is there a good way to get the current UserAgent so we can set EO.WebEngine.EngineOptions.Default.CustomUserAgent?

I want to do something like:
EO.WebEngine.EngineOptions.Default.CustomUserAgent = CurrentUserAgent + " MyCustomAgent/1.2.3.4";

At the moment we have to hard code the current user agent, and make sure to change it every time we update EO and Chromium version changes.
eo_support
Posted: Friday, April 26, 2024 5:54:03 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,133
Unfortunately no, there is no way to do that without actually creating a WebView. So the only way to do that is to:

1. Create a WebView, then use webView.EvalScript("window.navigator.userAgent) to get the user agent;
2. Stop the Engine. This is necessary for any changes of CustomUserAgent to take effect;
3. Set the new CustomUserAgent;
4. Continue to create WebView in your application;

Obviously, this might be a little over kill.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.