Page 1 of 1

Post Windows Event Message when DOM is loaded in WebViewGadget

Posted: Wed Mar 27, 2024 7:14 am
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.

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

Posted: Wed Mar 27, 2024 3:10 pm
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

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

Posted: Tue May 07, 2024 9:50 pm
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

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

Posted: Fri May 10, 2024 10:21 pm
by infratec
Until you are satisfied with the internal PB version, you can use mine.
There is a PostEvent implemented.

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

Posted: Sat May 11, 2024 9:14 am
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

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

Posted: Sat May 11, 2024 11:46 am
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.

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

Posted: Mon Feb 10, 2025 6:12 pm
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.