Build: v5.8.246
OS: Windows 10.0.19045
PS Version(s): 5.1.19041.1, 7.4.2, 7.3.4
As a bit of a novice, particularly in the Web side of things, I thought I'd share a couple points, that I struggled with, in case they are useful for others getting started with the WebView2 Control - or this may yield a better way of doing things from others.
Firstly, with regards to this previous post....
viewtopic.php?p=85777#p85777
..... many thanks for the changes made. The Webview2 control seems to be working well in PowerShell Studio now
When I looked, I couldn't find much information out there on using the control with PowerShell and was struggling to work out to interact with the Web page/site. With the old WebBrowser control I would often drill down through the document property of the object to get properties like innerHTML for example.
Code: Select all
$webbrowser1.document.activeelement.InnerHtml
So, as a rough equivalent to the above line to get InnerHTML.....
Code: Select all
$WebView21.ExecuteScriptAsync("window.chrome.webview.postMessage(document.documentElement.innerHTML);");
corewebview2
When I dropped the WebVIew2 control into an existing project, I did have problems with the control failing to initialise. Even though I was using the Initialize-WebView2Control helper function ("triggered from form_load) the initialisation failed with a corewebview2 in use error. It turned out this was due to me hard-coding a source (URL) in the GUI (for initial testing).
If no source (URL) is set in the PSS GUI then the initialisation worked fine. One slight issue here is that, having put a URL in this property in the GUI, I couldn't set it back to empty (null) .....
...... in the end, I had to remove the control and re-insert a new one to get rid of the URL.