How to specify a user agent for browser control?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

How to specify a user agent for browser control?

25 Dec 2018, 11:41

Hello,

Can specify a user agent for browser control?

Thanks.

Code: Select all

Gui Add, ActiveX, w980 h640 vWB, Shell.Explorer
WB.Navigate("https://autohotkey.com/boards/")
Gui Show
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: How to specify a user agent for browser control?

25 Dec 2018, 12:57

I don't think you can do that with Internet Explorer/ActiveX Controls,but.... you could do the following below,and update the page with the html retrieved using the method below...

To Verify user agent is modified in example below, comment out the line specifying user agent & see what happens.

Code: Select all


whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://www.google.com/search?btnI&q=apples+oranges", true)
whr.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")
whr.Send()
whr.WaitForResponse()
html := whr.ResponseText

;// write the Google Source to an HTMLfile
document := ComObjCreate("HTMLfile")
document.write(html)

;// loop through all the links
links := document.links
while (A_Index<=links.length, i:=A_Index-1)
	If !InStr(links[i].href, "about:")
		list .= i ") " links[i].innerText "`nURL: " links[i].href "`n`n"

MsgBox, %list%


Cheers.
live ? long & prosper : regards
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: How to specify a user agent for browser control?

26 Dec 2018, 03:40

Thank you.

My intention was to embed a web page, but I was having a problem. It is the embedded webpage that seems to notice that I am not opening it with a browser. It will prompt for additional warnings. I think this should be related to the user agent. If can provide user agent information, perhaps it will not prompt for some additional messages.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, peter_ahk, Spawnova and 347 guests