Reputation: 61
I am programming a program where I have several tabs. On each tab is a GeckoFX. I have tried a lot of things and unfortunately when I open the new tab and a second browser control is created and the user agent is changed, the user agent of the first browser control is changed as well.
Any ideas?
I would like to have one UserAgent per browsercontrol
Dim page As New TabPage("Tab" & Tabcontrol_Main.TabPages.Count.ToString)
Dim sUserAgent As String = "Tab" & Tabcontrol_Main.TabPages.Count.ToString
Tabcontrol_Main.TabPages.Add(page)
Dim browser As New GeckoWebBrowser
browser.Name = "browser" & Tabcontrol_Main.TabPages.Count.ToString - 1
GeckoPreferences.User.SetCharPref("general.useragent.override", RandomUserAgent(sUserAgent))
page.Controls.Add(browser)
browser.Dock = DockStyle.Fill
Upvotes: 1
Views: 334
Reputation: 6739
Setting useragent via GeckoPreferences is indeed global to the process.
If you are programmatically navigating for each tab, you could set the user agent in the request headers for each Navigate
call.
Navigate(string url, GeckoLoadFlags loadFlags, string referrer, MimeInputStream postData, MimeInputStream headers)
MimeInputStream headers= MimeInputStream.Create();
string simpleData = "User-Agent=hello";
headers.SetData(simpleData);
If you also want the user agent set when further navigation happens in each tab, then I guess, you would have to listen for each navigation and modify each one.
Upvotes: 1