Webview2 control - Chromium browser for Purebasic (Windows)

Everything else that doesn't fall into one of the other PB categories.
Justin
Enthusiast
Enthusiast
Posts: 725
Joined: Sat Apr 26, 2003 2:49 pm

Webview2 control - Chromium browser for Purebasic (Windows)

Post by Justin »

Update 11 April 2021
  • Updtated to the latest WebView2 SDK 1.0.774.44 / 1.0.824-prerelease
  • Added wv2_GetRuntimeVersionFromRegistry()
Webview2 Chromium browser control coded in PB, project is here:
https://github.com/omegakode/PBWebview2

Note: This is not a wrapper, is a port of the C/C++ API, so you have full access to the control.

To test it you need to run the WebView2 Runtime Installer(disable ad blockers):
https://developer.microsoft.com/en-us/m ... /webview2/

To test prereleases you need to install edge dev or canary:
https://www.microsoftedgeinsider.com/en-us/download

Now you can use either the stable SDK version or the prerelease version to try the experimental apis.

If you are only interested in the stable release install only the WebView2 runtime, the prerelease will not work.

If you are interested in both the stable and prerelease versions uninstall the WebView2 runtime and install edge dev only.

To use the stable release in code simply include the PBWebview2.pb file located in the project root folder, to use the prerelease version include the PBWebview2.pb file located in the prerelease folder.

The examples use the stable version include, but they also work with the prerelease one.

Then clone or download the project and simply run the examples with DPI aware enabled.
They are configured for 64bit, to test 32bit copy WebView2Loader.dll from the x86 folder to the examples folder.

You can interact from javascript easily through a purebasic object in 'PB_Host_Object.pb', see examples. You can load the content from the executable as a resource or from disk.

There are a lot of files in the project but the only one you need to include in your project is 'PBWebView2.pb'.
It may seem a little complicated at first because the creation is asynchronous but is simple, see 'basic_browser_async.pb' for the most basic example.

It uses the excellent VCall module from Wilbert.

License is MIT.

If you find it useful there is a donate button in the github readme.

Webview2 Reference:
https://docs.microsoft.com/en-us/micros ... /webview2/

Webview2 SDK, change extension to .zip
https://www.nuget.org/packages/Microsoft.Web.WebView2

Bootstrap example
Image
Ohm Browser
Image
Last edited by Justin on Sun Apr 11, 2021 11:22 am, edited 7 times in total.
User avatar
Caronte3D
Enthusiast
Enthusiast
Posts: 177
Joined: Fri Jan 22, 2016 5:33 pm
Location: Spain

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Caronte3D »

Justin wrote: To test it first you need to install MS Edge Dev Channel:
https://www.microsoftedgeinsider.com/en-us/download
So... the compiled PB program only work on a computer where Edge is installed?
User avatar
Kiffi
Addict
Addict
Posts: 1193
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Kiffi »

Caronte3D wrote:So... the compiled PB program only work on a computer where Edge is installed?
Yes, that is correct. Alternatively you can run the WebView2 Runtime installer (make sure that your ad blocker is turned off on this page).

But you can assume that Edge Chromium will be the default browser in future Windows installations.

Greetings ... Peter
Hygge
User avatar
Caronte3D
Enthusiast
Enthusiast
Posts: 177
Joined: Fri Jan 22, 2016 5:33 pm
Location: Spain

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Caronte3D »

I just tested the examples and everything works well, I'm thinking about the huge possibilities.
Thanks you so much! :wink:
User avatar
the.weavster
Addict
Addict
Posts: 1358
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by the.weavster »

Brilliant, thank you :!: :D
You've even exposed PB functions to JS 8)

Hopefully this will give Fred a flying start in making PB's official WebGadget much more modern in a (not too) future release.
User avatar
ChrisR
Enthusiast
Enthusiast
Posts: 311
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by ChrisR »

It's very interesting. I especially like the more modern look of the bootstrap example.
I would like to reproduce this kind of interface but i don't know how, it seems outside of my skills!
Thank you for sharing it in an open way, with the permissive MIT license

I noted the 5 processes msedgewebview2.exe
Do you know what they are used for and if there is a way to reduce memory usage (~42Mb for bootstrap) ?
Same question for the user data folder %LocalAppData%\Temp\AppName.exe.WebView2 (~19Mb)
At the same time, it's no bigger than that, these days.
Justin
Enthusiast
Enthusiast
Posts: 725
Joined: Sat Apr 26, 2003 2:49 pm

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Justin »

Hi ChrisR, about the bootstrap example i just copied a form example from the bootstrap page :D
https://getbootstrap.com/docs/4.5/components/forms/

The msedgewebview2.exe process are normal, some things are in external process it's more secure this way, although i don't know exactly what they are.

About memory usage you can pass Chromium flags when creating the control
https://peter.sh/experiments/chromium-c ... -switches/,
maybe disabling some things will help, i did it in the bootstrap.pb to disable web security, see main() proc.

About the user data folder, yes it's a hassle, but it seems tied to the control, there is a chapter on that in the documentation
https://docs.microsoft.com/en-us/micros ... datafolder
I guess a good option it's to set it to the user temp folder and delete it when the app exits, i did a function for that wv2_DeleteUserDataFolder() in Webview2_Helper.pb because it's a bit tricky it's used in the bootstrap.pb, window_Close() (commented).
Justin
Enthusiast
Enthusiast
Posts: 725
Joined: Sat Apr 26, 2003 2:49 pm

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Justin »

Just noticed that microsoft has introduced improvements in ram usage for Edge in the last Windows 10 2004 update:
https://www.zdnet.com/article/windows-1 ... nd-change/
I have not installed yet, will try it later to see if there is any difference.
Justin
Enthusiast
Enthusiast
Posts: 725
Joined: Sat Apr 26, 2003 2:49 pm

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Justin »

After the 2004 update i noticed a little improvement in ram usage, 38mb for the bootstrap app compiled exe, not sure if its significant enough.
User avatar
ChrisR
Enthusiast
Enthusiast
Posts: 311
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by ChrisR »

Justin wrote:Just noticed that microsoft has introduced improvements in ram usage for Edge in the last Windows 10 2004 update
I tested by myself to check the improvements in ram usage between Google Chrome v85.0.4183.83 and MS Edge 85.0.564.44
I confirm the gain, ~27% in my case with 5 open tabs
Chrome = 968 Mb, Edge = 706 Mb and for info Firefox v78.2.0esr = 838 Mb
I have 138 Mb of ram used with basic_browser_async and a youtube video in the single tab

If you wish to continue your examples, It would be nice to have the address bar and move forward or backward as it is done in WebView2Browser
zikitrake
Enthusiast
Enthusiast
Posts: 742
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain
Contact:

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by zikitrake »

This is simply awesome!
I hope MS doesn't leave the project in the lurch.
With this one we could dream with an official and updated WebGadget, right?

Thanks a lot, Justin!
Mike Yurgalavage
Enthusiast
Enthusiast
Posts: 118
Joined: Thu May 17, 2007 8:35 pm
Location: USA

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Mike Yurgalavage »

Just wanted to post here a sincere thanks for taking up this project and posting it.

I tested the examples and they all work here fine.

I have been looking for something like this for quite some time. THANK YOU!
Justin
Enthusiast
Enthusiast
Posts: 725
Joined: Sat Apr 26, 2003 2:49 pm

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Justin »

Hi, thanks for the feedback. Some updates:

Updated the code to the new 0.9.622.11 Webview2 SDK

resources.pb example now uses windows resources with .rc files, you have to add the file resources.rc in compiler options. The bootstrap example still uses the includebinary method.

Created a multitab browser to test the functions, supports all major standard shortcut keys and fullscreen.
I called it Ohm, it's in the Ohm Browser folder, uses pb vectoricons.
Image
Fred
Administrator
Administrator
Posts: 14348
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Fred »

Finally a new native solution is coming ! Thanks for the wrapper, we will look into it once it gets live.
User avatar
Kiffi
Addict
Addict
Posts: 1193
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Webview2 control - Chromium browser for Purebasic (Windo

Post by Kiffi »

Fred wrote:Finally a new native solution is coming ! Thanks for the wrapper, we will look into it once it gets live.
Image
Hygge
Post Reply