Page 3 of 13

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Sun Jan 31, 2021 8:04 am
by oyster
so bad, the installer for Evergreen Standalone Installer on windows 64bits is 92.7MB.

It reminds me of .NET framework of many years ago, which also needs to be installed by end-users manually, furthermore with not little disk occupation; as a result .NET does not populate quickly as expected.

There are ways to make application written in .NET portable, I mean copy and run even on PC without installing .NET framework. Is it possible for webview2?

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Sun Jan 31, 2021 12:14 pm
by fluent
Justin wrote:Hi, thanks for the feedback.

I updated to the latest WebView2 SDK 1.0.705.50 / 1.0.781-prerelease, see first post. There are some interesting new apis in the prerelease.

oyster,
Basically you need the WebView2 Runtime installed in the machine and the WebView2Loader.dll from the WebView2 SDK in the executable folder.

The distribution model is explained here:
https://docs.microsoft.com/en-us/micros ... stribution

WebView2 Runtime download:
https://developer.microsoft.com/en-us/m ... /webview2/
Thanks for the update!

2 quick questions, if you don't mind:
Is there a way to remove devtools (Inspect) from the context menu
Is there a way to intercept and stop a connection before it loads (similar to the Webgadget NavigationCallback)?

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Sun Jan 31, 2021 4:02 pm
by Justin
Hi fluent,

The devs tools entry is disabled through the settings object, put_AreDevToolsEnabled() method. In the bootstrap.pb example, in wvController_Created() procedure simply coment the line:
sett\put_AreDefaultContextMenusEnabled(#False)

This will enable the context menu, but since sett\put_AreDevToolsEnabled(#False) is later called the dev tools entry will not show.

Cancel navigation is done handling the NavigationStarting event, i have updated the basic_browser_async.pb example with that.
Basically after registering for the event you do something like this:

Code: Select all

Procedure wv_NavigationStarting(*this.WV2_EVENT_HANDLER, sender.ICoreWebView2, args.ICoreWebView2NavigationStartingEventArgs)
	Protected.i uri
	Protected.s suri
	
	Debug "Event NavigationStarting"

	If args\get_uri(@uri) = #S_OK
		suri = PeekS(uri)
		CoTaskMemFree_(uri)

		;CANCEL NAVIGATION
		If LCase(StringField(GetURLPart(suri, #PB_URL_Site), 2, ".")) = "google"
			MessageRequester("Purebasic", "Sorry google is banned.")
			args\put_Cancel(#True)
		EndIf 
	EndIf 
EndProcedure
See basic_browser_async.pb

oyster,
The only way to distribute in portable format without installing anything is through the 'Fixed Version distribution mode' as explained in the link, you download the fixed version package, put your executable in it an use CreateCoreWebView2EnvironmentWithOptions to set the browserExecutableFolder. But it takes 134MB compressed, 295MB uncrompessed :D
I think it's not a big deal to create an installer that installs the runtime only if it's not installed or prompt the user to install the runtime, although i would prefer that it came preinstalled with windows.
There have been requests for a stripped down version and for an in memory user data folder but i don't see it happening.

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Sun Jan 31, 2021 4:24 pm
by fluent
Thanks a lot Justin - I've just tried the new basic_browser_async.pb and it's working great, but would you know if it can also cancel connections to page subresources (for instance, allowing navigation to http://www.purebasic.com but cancelling the loading of the PureBasic logo at https://www.purebasic.com/img/pb-logo-white.png), or is there another event for that?

(This is mainly out of curiosity BTW - I certainly don't want to waste your time if there is no "easy" solution for that)

EDIT: Ah, nevermind, found your resources.pb example. Fantastic!

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Wed Feb 17, 2021 8:12 am
by plouf
Very good work

is there a manual of the available function?

can you retrieve html (content) of page that has been loaded ?

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Wed Feb 17, 2021 11:48 am
by Justin
Hi plouf,

Currently the only way to get the HTML content it's trhough executing javascript, a direct interface method has been requested in the webview forum.

To get all the content use:

Code: Select all

script = "new XMLSerializer().serializeToString(document);"
To get only the body:

Code: Select all

script = "document.body.outerHTML;"
To test it go to the bootstrap.pb example, and in the menu_GetPassword_Click() procedure replace the script with one of those and you will get the result.

Note that wv2_Core_ExecuteScriptSync() is a helper function that can only be called in a non binded event procedure, otherwise you will have to use the native ExecuteScript method and get the result in the script executed event handler, i'll update the examples later.

As for the manual i guess is the win32 reference or the getting started part:
https://docs.microsoft.com/en-us/micros ... 1.0.705.50
https://docs.microsoft.com/en-us/micros ... rted/win32

Once you get an object you can use all its methods, all the interfaces are ported to pb. The examples are a good start i covered the most important things.

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Wed Feb 17, 2021 5:06 pm
by plouf
Thanx
But i cant think i can inject javascript to an existing page

What i am trying to o is to get a page html in order to extract some data

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Fri Mar 19, 2021 12:18 pm
by the.weavster
:!:
Microsoft has started auto-installing WebView2 on Windows 10 PCs 8)

*Edit
... if they have Office 365 installed

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Fri Mar 19, 2021 2:00 pm
by Bitblazer
plouf wrote:What i am trying to o is to get a page html in order to extract some data
Check out the Html Agility Pack.

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Tue Mar 30, 2021 8:34 am
by fluent
Hi, my Windows just got upgraded to version 20H2, which ships the Webview2 control by default (yay!), so I removed my installation of Edge Beta, but now my apps can no longer find the Webview2 control unfortunately:

Code: Select all

---------------------------
Error
---------------------------
System webview2 not found - Install MS Edge Runtime.
---------------------------
OK   
---------------------------
I just manually verified that it is present in this path: C:\Program Files (x86)\Microsoft\Edge

Any ideas? Thanks!

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Tue Mar 30, 2021 2:19 pm
by Justin
Hi,

is that error the result of this code?

Code: Select all

	If wv2_GetBrowserVersion("") = ""
		MessageRequester("Error", "MS Edge not found, install MS Edge Runtime.")
		End 
	EndIf
if so i think you can just comment it and it should work.
I'll take a closer look later.

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Tue Mar 30, 2021 9:35 pm
by Justin
As said in a post above the runtime is only installed with Microsoft 365 and Microsoft Office for now.

To check if the runtime is installed the regkey 'pv' in:
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}

must exist with a value.

Explained here:
https://docs.microsoft.com/en-us/micros ... stribution

I'll update the code with some functions, wv2_GetBrowserVersion() only checks if Edge browser is installed so it's not reliable.
It's a bit of a mess because applications can run without the runtime installed but with dev channel installed, although dev it's only for developers to test new functions, the end user must have always the stable runtime installed.

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Tue Mar 30, 2021 10:19 pm
by fluent
Ah, understood. Thank you for the clear reply!

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Sun Apr 11, 2021 11:23 am
by Justin
Hi, i was a bit dense wv2_GetBrowserVersion() is perfectly reliable to get the runtime version, but i also added wv2_GetRuntimeVersionFromRegistry() to get it from the registry.

Updated to the last Webview2 SDK 1.0.774.44 / 1.0.824-prerelease

Re: Webview2 control - Chromium browser for Purebasic (Windo

Posted: Mon Apr 12, 2021 7:10 am
by Lunasole
I didn't had a case to use browser in some PB apps (few times I only used "headless" browsers), but just curious looking at this thread, is this control alternative to CEF, or they are different? Thanks if someone can describe a bit.

https://bitbucket.org/chromiumembedded/cef