Post Windows Event Message when DOM is loaded in WebViewGadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post Windows Event Message when DOM is loaded in WebViewGadget

Post by Tranquil »

Topic should say it all.
Yes, I know it can be done with BindWebViewGadget but it is a bit more complex if you have more then one WebViewGadgets open.
Maybe add an EventType for the WebViewGadget like #PB_EventType_DOMReady or something like this.

I saw that the WebViewGadget needs an EventLoop anyway to work.
Tranquil
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Post Windows Event Message when DOM is loaded in WebViewGadget

Post by Quin »

Tranquil wrote: Wed Mar 27, 2024 7:14 am Maybe add an EventType for the WebViewGadget like #PB_EventType_DOMReady or something like this.
+1
User avatar
Kiffi
Addict
Addict
Posts: 1502
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Post Windows Event Message when DOM is loaded in WebViewGadget

Post by Kiffi »

+1 That would be helpful.

Until then, you could make do with the CoreWebView2 and add_NavigationCompleted? However, I have no idea how this could be implemented.

Code: Select all

OpenWindow(0, 100, 100, 400, 400, "Hello", #PB_Window_SystemMenu)

WebViewGadget(0, 0, 0, 400, 400, #PB_WebView_Debug)

; Get the ICoreController interface 
;
Controller.ICoreWebView2Controller = GetGadgetAttribute(0, #PB_WebView_ICoreController)

; Get the ICoreWebView2 interface 
;
Controller\get_CoreWebView2(@Core.ICoreWebView2)
Core\Navigate("https://www.purebasic.com")

Core\add_NavigationCompleted( ??? , ??? ) ; <----------------------

DataSection
	IID_ICoreWebView2Controller2:
	Data.l $C979903E
	Data.w $D4CA, $4228
	Data.b $92, $EB, $47, $EE, $3F, $A9, $6E, $AB
EndDataSection

If Controller\QueryInterface(?IID_ICoreWebView2Controller2, @Controller2.ICoreWebView2Controller2) = #S_OK
  Debug "ICoreWebView2Controller2 found: " + Controller2
Else
  Debug "Can't query ICoreWebView2Controller2"
EndIf

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Hygge
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Post Windows Event Message when DOM is loaded in WebViewGadget

Post by infratec »

Until you are satisfied with the internal PB version, you can use mine.
There is a PostEvent implemented.
dige
Addict
Addict
Posts: 1405
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Post Windows Event Message when DOM is loaded in WebViewGadget

Post by dige »

@infratec: I understand that you have created a solution that posts an event when the DOM has finished loading?
Unfortunately, I didn't find anything in the search. Can you please post a link?

kind regards

Dige
"Daddy, I'll run faster, then it is not so far..."
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Post Windows Event Message when DOM is loaded in WebViewGadget

Post by infratec »

It is part of this thread from Justin:

https://www.purebasic.fr/english/viewtopic.php?t=75898


I created a WebView2Gadget() out of this stuff.
Somewhere arround page 8.

Here is the link for direct download:
PBWebView2 & WebView2Gadget

There are 2 Events:
#PB_EventType_TitleChange when a navigation is completed
and
#PB_EventType_Up when the webview2 stuff is able to work.


I will soon update the file, that the required dll is no longer needed. it is then statically linked.

File is updated. But now much larger because of the static libs.
nsstudios
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: Post Windows Event Message when DOM is loaded in WebViewGadget

Post by nsstudios »

+1
Went to forum to check if this was possible.
Would be nice if it were.
The workaround with binding doesn't really work if you're interfacing with a third-party webpage. At least, I've not found a way to inject/append/prepend my own html without it overwriting the html from the already loaded page.
Post Reply