set UserAgent in Webview2 - user-agent

i am creating a desktop application with Webview2 as browser. I have to change the user agent to get data from a website. My control name is Webview21 for the browser control. I got the error message System.NotImplementedException: 'Unable to cast to Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Settings2.
This may happen if you are using an interface not supported by the version of the WebView2 Runtime . But i have the latest evergreen version.
What is the solution?
Public Async Sub InitializeBrowser()
Dim strip As String = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62 seakayak-navigator"
Dim opts As New CoreWebView2EnvironmentOptions With {.AdditionalBrowserArguments = "--disable-web-security --allow-file-access-from-files --allow-file-access "}
Dim userDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\SeakayakNavigator"
Dim env = Await CoreWebView2Environment.CreateAsync(Nothing, userDataFolder)
Await WebView21.EnsureCoreWebView2Async(env)
Application.DoEvents()
WebView21.Width = Fmenu.Width
WebView21.Height = Fmenu.Height
WebView21.Top = 0
WebView21.Left = 0
WebView21.BringToFront()
WebView21.CoreWebView2.Settings.UserAgent = strip
' Add any initialization after the InitializeComponent() call.
AddHandler WebView21.NavigationCompleted, AddressOf webview21_navigationCompleted
WebView21.CoreWebView2.AddHostObjectToScript("Bridge", New Bridge())
End Sub

CoreWebView2.Settings.UserAgentis not supported in the current stable release (version 1.0.818.41).
If you want to use CoreWebView2.Settings.UserAgent you must install the pre-release version, currently version 1.0.865-prerelease.
You can follow the directions here: To install a pre-release version
That also means that you must use Microsoft Edge CANARY build
which you can get here: Microsoft Edge Insider Channels
Unfortunately, you might have to uninstall the 'WebView2 runtime' (which I think is a bug in the WebView2 package).
Update:
Now the latest stable version supports setting the
useragent.

Related

Change user-agent python + selenium + firefox

I am creating a script with python + selenium + firefox. While loading firefox I am including the following addon - https://github.com/muzuiget/user_agent_overrider . It overrides user-agent with just one click.
I need to simulate that from my code. So what i need is the following:
1. I open a page with default user-agent.
2. Script should change the user-agent while Firefox is still running (using the addon from above) and visits the same page.
I did look at the source code of the addon, but I just can't trigger the right function :)
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
ff_profile = FirefoxProfile()
ff_profile.set_preference("general.useragent.override", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36")
driver = webdriver.Firefox(firefox_profle = ff_profile)
driver.get('http://www.whatismybrowser.org')
There is a typo in the last answer.. i did a stupid copy/paste and it took me 20 minutes to realise it -_-
driver = webdriver.Firefox(firefox_profle = ff_profile)
should be
driver = webdriver.Firefox(firefox_profile = ff_profile)

MAPI Error : The information store could not be opened. [MAPI 1.0 - [MAPI_E_LOGON_FAILED(80040111)]] [duplicate]

We are upgrading our server to Windows 2012 from 2003.
Our application use CDO 1.21 and MAPI to send mails, I know I have to use SMTP/ OOM/AWS. At this late stage I don't want to do make changes in our programs right now - there are 80+ :)
When I am going to MS site to download CDO 1.21, Windows 2102/Exchange Server 2010 SP3 is not specified under supported platforms.
I am able to download CDO 1.21 for Win 2012. But now when I am connecting via MAPI, System is throwing error:
The information store could not be opened. [MAPI 1.0 - [MAPI_E_LOGON_FAILED(80040111)]]
MAPI Code :
Set objMAPI = New MAPI.Session
objMAPI.Logon ShowDialog:=False, NewSession:=False, ProfileInfo:=gobjINI.gstrExchangeServer & vbLf & gobjINI.gstrProfile
'Add a new mesage to the OUtbo Messages Collection
Set objMSG = objMAPI.Outbox.Messages.Add
Error is thrown on third line: Set objMSG = objMAPI.Outbox.Messages.Add.

Any way to update the browser list in a Web/Load Test Project in Visual Studio 2015?

I created a Web Performance and Load Test Project in Visual Studio 2015. I created a Load test and in the wizard it gives me a list of available browsers to simulate. The browsers it lists are extremely old (Chrome 2, Netscape).
Anyway to update the list?
The list of browsers is taken from the files in a Visual Studio directory. For the 2013 version the directory is as follows. Similarly named directories are used for other Visual Studio versions.
c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Templates\LoadTest\Browsers
The actual *.browser files contain XML and can be edited with Notepad etc. If you know the characteristics of the browser you want to simulate then it should be simple to copy and modify an existing file.
I have not seen any web page that specifies the details of the *.browser files. Part of their content is the "user agent string" and web searching should readily find the string for many new browsers.
Be aware that standalone web tests are run differently than those run within a load test. Standalone web tests are run as if by a default browser. Have not found any way to specify that browser. Many characteristics of the real browser may be irrelevant but the user agent string may be important. I wrote the following plugin when testing a web site for it behavior when accessed by a mobile phone or a tablet.
[System.ComponentModel.Description(
"Set the user agent to a fixed value if called from a web test. For a load "
+ "test leave it alone so the value from the browser mix is used.")]
public class SetUserAgent : WebTestPlugin
{
public override void PreRequest(object sender, PreRequestEventArgs e)
{
if (e.WebTest.Context.ContainsKey("$LoadTestUserContext"))
{
// Leave the user agent alone, it will be set by the load test's browser mix.
}
else
{
const string UserAgent = "User-Agent";
if (e.Request.Headers.Contains(UserAgent))
{
e.Request.Headers.Remove(UserAgent);
}
// Samsung Galaxy Tab 3 7inch.
// e.Request.Headers.Add(UserAgent, "Mozilla/5.0 (Linux; U; Android 4.2.2; en-gb; SM-T110 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30");
// Sony Xeperia S, Ion. 360x640 pixels.
e.Request.Headers.Add(UserAgent, "Mozilla/5.0 (Linux; U; Android 4.0; en-us; LT28at Build/6.1.C.1.111) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
}
}
}
It should be easy to set user agent strings for other devices.

Reliable way to get Windows Version from registry

I'm checking the windows version in an installer (made with NSIS) by checking the following registry key:
HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
According to this post and this page from MSDN, the currentVersion number for Windows 10 should be 10.0.
I just installed the Windows 10 Pro Insider Preview and the version number given in the registry is still 6.3, instead of 10.10 as it should.
Is there another reliable way in registry to detect Windows 10?
Instead of reading the value CurrentVersion, read the new values CurrentMajorVersionNumber (which is 10) and CurrentMinorVersionNumber (which is 0) under Windows 10. Those 2 keys are new in Windows 10 to detect Windows Version from Registry.
There's also a human-readable string in the registry called "ProductName"
using Microsoft.Win32;
private string getOSInfo()
{
string registry_key = #"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
var key = Registry.LocalMachine.OpenSubKey(registry_key);
var value = key.GetValue("ProductName");
return value.ToString();
}
Try
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ReleaseId
Which gives me 10 and 1709.
See Peter Bright's article at https://arstechnica.com/information-technology/2014/11/why-windows-10-isnt-version-6-any-more-and-why-it-will-probably-work/ for more insight on why you see the answers you do. As you already saw from #magicandre1981, the CurrentMajorVersionNumber key will give you the "10" you want. You can get 10.0 from System.Environment.OSVersion if the application manifest explicitly designates your app for Windows 10, as stated in the referenced article. Without it, Environment.OSVersion will give you 6.2.9200, which is the same as Windows 8. So, your Windows 10 version is 10.0, 6.3, or 6.2, depending on how you ask the question.

Opening an order in CRM 2013 sometimes gives a blank page

Sometimes CRM 2013 decides to give me the following error when opening an Order (and presents me with an empty page, but with the top navigation bar intact):
<CrmScriptErrorReport>
<ReportVersion>1.0</ReportVersion>
<ScriptErrorDetails>
<Message>Unable to get property 'ClientVariables' of undefined or null reference</Message>
<Line>2</Line>
<URL>/_common/JsProvider.ashx?ids=1959345455-451858892-1713948411-1279630416-1250882489-367493978-19173614-574022791-696891199-2007586035-1552783829&ver=-976933632</URL>
<PageURL>/main.aspx?etc=1088&extraqs=%3f_gridType%3d1088%26etc%3d1088%26id%3d%257b76EB6220-FB46-E311-93F3-00155D5752A9%257d%26rskey%3d674031362&pagemode=iframe&pagetype=entityrecord&rskey=674031362 </PageURL>
<Function>anonymous(){returnthis.get_$L_0().ClientVariables}</Function>
<CallStack>
<Function>anonymous(){returnthis.get_$L_0().ClientVariables}</Function>
</CallStack>
</ScriptErrorDetails>
<ClientInformation>
<BrowserUserAgent>Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C)</BrowserUserAgent>
<BrowserLanguage>en-US</BrowserLanguage>
<SystemLanguage>en-US</SystemLanguage>
<UserLanguage>en-US</UserLanguage>
<ScreenResolution>1920x1080</ScreenResolution>
<ClientName>Web</ClientName>
<ClientTime>2013-11-11T17:32:05</ClientTime>
</ClientInformation>
<ServerInformation>
<OrgLanguage>1033</OrgLanguage>
<OrgCulture>1043</OrgCulture>
<UserLanguage>1033</UserLanguage>
<UserCulture>1043</UserCulture>
<OrgID>{54131DE3-6D18-44FD-B4D0-0A9E87DA3E9D}</OrgID>
<UserID>{E369A31E-3446-E311-93F2-00155D5752A9}</UserID>
<CRMVersion>6.0.0.809</CRMVersion>
</ServerInformation>
</CrmScriptErrorReport>
This will keep on happening until I fiddle around with the cache or open another organisation. I'm still not sure what exactly resolves it. I do have custom code on the Order form but I often go days without getting the error. Any idea how I can try to locate the cause of this error and whether it has something to do with my custom code or whether its a bug in CRM 2013?
Thanks.
I've faced same issue with quote entity, when I ask my CRM users to clean temporary files for the browsers they never reported the issue.
In my case MSD 2013 On-premise

Resources