From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use WebView2 control in LabView?

Solved!
Go to solution

I need to have a web browser (and its contents) within the LabView environment.

The existing IWebBrowser2 uses the Internet Explorer 11 compatibility which is getting old...

As far as I know, the WebView2 control can be used only in Visual Studio or similar environment.

Is it some way that I can use it inside Labview?

 

Message 1 of 32
(7,913 Views)

I haven't tried it myself, but I took a look at the documentation (https://docs.microsoft.com/en-us/microsoft-edge/webview2/ ). Based on that information, it appears you could use the .NET Windows Forms version of the control, especially since it supports the ("old") .NET Framework 4.6.2 or higher. LabVIEW supports hosting assemblies in that version of the CLR so there's a good chance you could make it work if you meet the runtime and OS requirements.

 

In your shoes I would download the control (https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.705.50), install the WebView2 runtime and supported version of Edge and try it out. Looking inside the nuget package (its just a zip), I can see you're possibly after the Core and WinForms assemblies. But a trial would be needed to clarify any other dependencies (.NET or native).

Message 2 of 32
(7,889 Views)

Thank you @tyk007,

 

I have already done that.

Unfortunately, the WebView2 runtime does not "add" some controls in .net controls, so that I can handle them inside LabView...

 

Thanks again,

0 Kudos
Message 3 of 32
(7,837 Views)

Maybe you could be more specific on:

 

- what you have done so far

- what you are trying to achieve

- your existing code that demonstrates your progress.

 

Otherwise general questions won't get you a lot of detailed answers.

0 Kudos
Message 4 of 32
(7,825 Views)

Thank you tyk0007,

 

I tried to read some webpage, for example (https://tv.yousee.dk/tv-guide.com) by using the "WebBrowser" form the "System.Windows.Forms (4.0.0.0)" .net control.

The answer was that "...it's no longer support this browser. We recommend that you use the latest version of Google Chrome."

 

I have already installed the WebView2 runtime, expecting that it will "add" some controls in .net controls, so that I can handle them inside LabView.

 

And the question is: Is there a way that I can use the "WebView2" .net controls (which support the modern browser environment) inside Labview?

 

Thanks again,

0 Kudos
Message 5 of 32
(7,774 Views)
Solution
Accepted by yorphanos

I just got this working. I followed what Microsoft says here and installed the runtime. I then downloaded the webview2 package from the nuget repository. Once that was done i change the nupkg extension to .zip and then unzipped it. I then added a .net control on the LV front panel. I linked it to the webview2 control, and shown below is the block diagram with some comments.

 

edit: you can probably remove the while loop around the CoreWebView reference. That was added before I got the wait on the async call to work correctly and I didn't remove it.

 

Hope this helps:

 

GregFreeman_0-1619578383411.png

 

Message 6 of 32
(7,690 Views)

As an update, i'm finding the method used in my previous post sometimes hangs up. I'm guessing it has to do with the synchronization context of the Wait() method but I can't be sure.

 

Either way, using the source property to initialize the browser and then polling for a valid reference seems to work more consistently:

 

GregFreeman_0-1619626983431.png

 

Message 7 of 32
(7,668 Views)

Thank you!
It is working!
Although it has some side effects... The folders visibility is missing when you want to open (using "Ctrl+O") for example a file!

Some times also the LabView freezes...
But in any case it is a good start!!!
Thank you again!

Download All
0 Kudos
Message 8 of 32
(7,655 Views)

@yorphanos wrote:

Thank you!
It is working!
Although it has some side effects... The folders visibility is missing when you want to open (using "Ctrl+O") for example a file!

Some times also the LabView freezes...
But in any case it is a good start!!!
Thank you again!


Please see me latest reply, not the one you marked as an answer. Does that freeze up as well? I had better results with that.

 

Very interesting about the open file dialog...Not sure what's going on there.

 

Edit: I removed the CLFN calls which are being used to set the DLL paths. I then copied the WebView2 DLLs and the Releases directory into C:\Program Files (x86)\National Instruments\LabVIEW 2019. This works. That means the problem is being caused by the calls that are adding paths to the DLL search path.

 

So you can either troubleshoot that, or just copy the DLLs into the LabVIEW directory to make it work in the development environment, then remove the CLFNs. This is a bit ugly having to copy into C:\Program Files but it's what we're stuck with unless the WebView2 project owners allow the path to be set programmatically.

Message 9 of 32
(7,648 Views)

I can't find the ".net Constructor" for the "Uri" Constructor Node...

In which Assembly / Object can that be found?

0 Kudos
Message 10 of 32
(7,641 Views)