Webview 5.11 presenting blank window from local intranet site, C# WPF - c#

I'm trying to set a very simple WPF application that will only pull a local HTML page that is a live
and functioning as expected, hosted in our work place.
we have no internet connection within the LAN.
I added succesfully WebView 5.11 (also tried 6.0 with same results) and added the following code:
<WPF:WebView Source="https://localSiteAddress" x:Name="wv" IsPrivateNetworkClientServerCapabilityEnabled="true"/>
this results in a blank page.
I was triyng to do the same through the code CS file and I added the following code:
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
var wv = new WebView();
wv.IsPrivateNetworkClientServerCapabilityEnabled = true;
wv.Source = new Uri("https://localSiteAddress");
grid.Children.Add(wv);
wv.BringIntoView();
}
same behavior
I was trying to access multiple local intranet websites with the same result.
Note: when i use an external PC with Internet connection i nanage to access websites
Anyone pelase help :) any suggestion will be so welcome ... I wasted 48 hours already:)
Thanks

Related

UIAutomation throws AccessViolationException on Windows 11

The issue:
We have an application written in C# that uses UIAutomation to get the current text (either selected or the word behind the carret) in other applications (Word, OpenOffice, Notepad, etc.).
All is working great on Windows 10, even up to 21H2, last update check done today.
But we had several clients informing us that the application is closing abruptly on Windows 11.
After some debugging I've seen some System.AccessViolationException thrown when trying to use the TextPatternRange.GetText() method:
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
What we've tried so far:
Setting uiaccess=true in manifest and signing the app : as mentionned here https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/350ceab8-436b-4ef1-8512-3fee4b470c0a/problem-with-manifest-and-uiaccess-set-to-true?forum=windowsgeneraldevelopmentissues => no changes (app is in C:\Program Files\
In addition to the above, I did try to set the level to "requireAdministrator" in the manifest, no changes either
As I've seen that it may come from a bug in Windows 11 (https://forum.emclient.com/t/emclient-9-0-1317-0-up-to-9-0-1361-0-password-correction-crashes-the-app/79904), I tried to install the 22H2 Preview release, still no changes.
Reproductible example
In order to be able to isolate the issue (and check it was not something else in our app that was causing the exception) I quickly made the following test (based on : How to get selected text of currently focused window? validated answer)
private void btnRefresh_Click(object sender, RoutedEventArgs e)
{
var p = Process.GetProcessesByName("notepad").FirstOrDefault();
var root = AutomationElement.FromHandle(p.MainWindowHandle);
var documentControl = new
PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Document);
var textPatternAvailable = new PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, true);
var findControl = new AndCondition(documentControl, textPatternAvailable);
var targetDocument = root.FindFirst(TreeScope.Descendants, findControl);
var textPattern = targetDocument.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
string text = "";
foreach (var selection in textPattern.GetSelection())
{
text += selection.GetText(255);
Console.WriteLine($"Selection: \"{selection.GetText(255)}\"");
}
lblFocusedProcess.Content = p.ProcessName;
lblSelectedText.Content = text;
}
When pressing a button, this method is called and the results displayed in labels.
The method uses UIAutomation to get the notepad process and extract the selected text.
This works well in Windows 10 with latest update, crashes immediately on Windows 11 with the AccessViolationException.
On Windows 10 it works even without the uiaccess=true setting in the manifest.
Questions/Next steps
Do anyone know/has a clue about what can cause this?
Is Windows 11 way more regarding towards UIAutomation?
On my side I'll probably open an issue by Microsoft.
And one track we might follow is getting an EV and sign the app itself and the installer as it'll also enhance the installation process, removing the big red warnings. But as this is an app distributed for free we had not done it as it was working without it.
I'll also continue testing with the reproductible code and update this question should anything new appear.
I posted the same question on MSDN forums and got this answer:
https://learn.microsoft.com/en-us/answers/questions/915789/uiautomation-throws-accessviolationexception-on-wi.html
Using IUIautomation instead of System.Windows.Automation works on Windows 11.
So I'm marking this as solved but if anyone has another idea or knows what happens you're welcome to comment!

C# .NET: Scraping dynamic (JS) websites

After hours of fails, I am coming here. I need to scrape a dynamically generated webpage (made using Vue.JS, but I would prefer not to share the link).
I have tried multiple approaches (1, 2, 3). None of them works on this webpage.
The most promising solution was using Selenium and PhantomJS. I tried it like this and I'm not sure why it's not even working for Google:
private void button1_Click(object sender, EventArgs e) {
PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
service.IgnoreSslErrors = true;
service.LoadImages = false;
service.ProxyType = "none";
var driver = new PhantomJSDriver(service); // I also tried: new PhantomJSDriver();
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10);
driver.Url = "https://google.com";
driver.Navigate();
var source = driver.PageSource;
textBox1.AppendText(source);
}
Did not work:
I also tried with a WebBrowser Control, but the page never fully loads:
(EDIT: I found out WebBrowser just instantiates IE, and after trying to open the target website in standalone IE browser, the webpage also never loads completely, so it makes sense to see the same behaviour inside WebView. I think I am bound to Selenium&PhantomJS due to this fact.)
Surely this shouldn't be so complicated. How to do it properly?
if you need to scrape a website you can use ScrapySharp scraping framework. You can add it to a project as a nuget.
https://www.nuget.org/packages/ScrapySharp/
Install-Package ScrapySharp -Version 2.6.2
It has many useful properties to access different elements on the page.For example to access the entire HTML of the page you can use the following:
ScrapingBrowser Browser = new ScrapingBrowser();
WebPage PageResult = Browser.NavigateToPage(new Uri("http://www.example-site.com"));
HtmlNode rawHTML = PageResult.Html;
Console.WriteLine(rawHTML.InnerHtml);
Console.ReadLine();

an Error in Google Translation Api V2

Last night I wanted to start a new project, but with a strange Error I face !!!
If anyone has worked with Translation API, please help!
The Error Tip is :
The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
and My Codes are Here too.
private void Form1_Load(object sender, EventArgs e)
{
TranslationClient cli = TranslationClient.Create();
var word = cli.TranslateText("hello","fa");
MessageBox.Show(word.TranslatedText.ToString());
}

How to Join a Teamspeak Server through: Button Click Event - Windows Form

Process: I'm currently developing a Game Launcher through Visual Studio. After being successful with everything so far I have come across "A coding idea" that I just can't figure out how to code.
Attempts:
Base Line (Opens Teamspeak):
private void btnFoxedTs_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(#"C:\Program Files\TeamSpeak 3 Client\ts3client_win64.exe");
}
Joining Server (Through IP):
private void btnFoxedTs_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(#"C:\Program Files\TeamSpeak 3 Client\ts3client_win64.exe://voice.teamspeak.com:9987");
}
Thrown Error:
Any Ideas???
My Plans: I'm wanting to make the button "Auto-Connect" to the Teamspeak server upon, the "Teamspeak Client" opening. Without the user needing to input a Bookmark, Server IP, Anything like that.
If Possible: If this works, would I be able to include a Teamspeak server password, so when they click the button is "Auto-Connects" with a pre-imputed password (Without the user needing to type a password).
Just use the ts3server:// url to run the TS3 client, you can provide all nessecary parameters there.
Basic example:
System.Diagnostics.Process.Start("ts3server://voice.teamspeak.com?password=serverPassword");
The TeamSpeak client registeres itself for the protocol and will be started by Windows it is invoked. You don't even need to bother with the path to the client.
More parameters are described in the official FAQ.
After going through those posts that #GeraldSchneider gave me, I found found this "ts3server://ts3.hoster.com:9987" Parameter URL used in linking your Teamspeak to a Webpage. After playing around a bit, trying out different methods,
I came up with this code:
private void btnFoxedTs_Click(object sender, EventArgs e)
{
var p = new System.Diagnostics.Process();
p.StartInfo.FileName = "C:\\Program Files\\TeamSpeak 3 Client\\ts3client_win64.exe";
p.StartInfo.Arguments = "ts3server://voice.teamspeak.com";
p.Start();
}
One thing that I must say, after reading the Teamspeak Forums saying that "Command-Line Parameters are not possible", it feels good to get this working.
What it does:
The Code opens up your 'Teamspeak Client' and 'Auto-Connects' to the server that is implemented. The Server opens up in a "new-tab" (If you are connect to other servers) and joined with your pre-set 'Nickname'.
Disclaimer Note: I used the "Default Teamspeak Server Ip" in this post so my personal Teamspeak isn't displayed.

Automating Google Maps in C# Web Browser (issue executing javascript properly)

NOT using API
I am currently attempting to use a web browser in C# to load google maps and automatically focus on my current location, however, for some reason I cannot get this to work properly. The idea is simple. Load Google maps, and either execute the script to focus on my current location:
mapBrowser.Document.InvokeScript("mylocation.onButtonClick");
Or, invoke the button click through an HtmlElement:
HtmlElement myLocationButton = mapBrowser.Document.GetElementById("mylocation");
myLocationButton.InvokeMember("click");
But, of course neither of these methods actually work correctly, the coordinates returned are incorrent and the map never actually focuses. Any ideas on how I can fix this issue properly? The scripts aren't invoked until after the document is actually loaded:
private void mapBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if(mapBrowser.Url.ToString() == "https://www.google.com/maps/preview/")
{
try
{
//HtmlElement myLocationButton = mapBrowser.Document.GetElementById("mylocation");
//myLocationButton.InvokeMember("click");
mapBrowser.Document.InvokeScript("mylocation.onButtonClick");
//mapBrowser.Document.InvokeScript("focus:mylocation.main");
}
catch (Exception ex)
{
MessageBox.Show("Error Invoking Script: " + ex.Message);
}
}
}
so I don't believe that is the cause of my problem. Even more frustratingly, the auto-focus works fine if I click the button manually.
Any help is appreciated, thank you!
(NOTE, you may have to go into IE and allow Google maps access to your location in order to replicate this issue properly)
I've had problem few times that WebBrowser control uses too old version of IE. You need to modify registry to get it to use newer version of IE.
I tried "https://www.google.com/maps/preview/" with both IE 8 and 9 and it gave me an error, but it works on IE 10.
See: http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

Categories