[Resolved] PB 6.30 WebViewGadget & Tab Key freeze

Just starting out? Need help? Post your questions and find answers here.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 644
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

[Resolved] PB 6.30 WebViewGadget & Tab Key freeze

Post by falsam »

Hello,

I am currently exploring WebViewGadget (PB 6.30) and how to communicate variables between JavaScript and PureBasic.

This code displays a small form consisting of three HTML tags: First Name, Last Name, and a “Submit” button to send the data to PureBasic variables.

Code: Select all

EnableExplicit

Enumeration
  #app
  #webview
  #json
EndEnumeration

; HTML Code
Define Html.s = ~"<!DOCTYPE html>\n" +
                ~"<html>\n" +
                ~"<body>\n" +
                ~"\n" +
                ~"<label>First name:</label><br>\n" +
                ~"<input type=\"text\" id=\"fname\"><br>\n" +
                ~"<label>Last name:</label><br>\n" +
                ~"<input type=\"text\" id=\"lname\"><br><br>\n" +
                ~"<input type=\"submit\" id=\"submit\" value=\"Submit\">\n" +
                ~"\n" +
                ~"<script>\n" +
                ~"const [fname, lname, submit] = document.querySelectorAll(\"#fname, #lname, #submit\");\n" +
                ~"\n" +                
                ~"document.addEventListener(\"DOMContentLoaded\", () => {\n" +
                ~"    submit.addEventListener(\"click\", () => {\n" +
                ~"        window.formSubmit(fname.value, lname.value).then(result => {\n" + 
                ~"			fname.value = '';\n" +
                ~"			lname.value = '';\n" +
                ~"        })\n" +
                ~"    });\n" +
                ~"});\n" +
                ~"</script>\n" +
                ~"</body>\n" +
                ~"</html>\n"

; Event
Define Event

Declare DataReceived(JSONBuffer.s)

OpenWindow(#app, 100, 100, 400, 400, "Simple Form", #PB_Window_SystemMenu | #PB_Window_Invisible)

; Webview option debug (view console)
WebViewGadget(#webview, 0, 0, 400, 400, #PB_WebView_Debug)

; Insert code HTML and assign callback
SetGadgetItemText(#webview, #PB_WebView_HtmlCode, Html)
BindWebViewCallback(#webview, "formSubmit", @DataReceived())

; Show the window once the webview has been fully loaded
HideWindow(#app, #False)

; WebViewGadget callback
Procedure DataReceived(JSONBuffer.s)    
  Protected buffer.s = ""
  
  Dim JsonParameters.s(0)
  ParseJSON(#json, JSONBuffer)
  ExtractJSONArray(JSONValue(#json), JsonParameters())
  
  Debug "First Name : " + JsonParameters(0)
  Debug "Last name  : " + JsonParameters(1)
  
  ProcedureReturn UTF8(~"{ \"buffer\": "+ Chr(34) + buffer + Chr(34)+ "}")
EndProcedure

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

■ You can test it by entering your first name, then your last name, and clicking the Submit button. You will see the result in the debug window. It works! YEahhhh i'm happy 🌞

■ But there's a problem 😞. Now press the tab key several times in the form. The application freezes.

I don't see any errors in this small code and there are no errors in the JS debug console.

Could there be a bug with the WebViewGadget ? Or is it me ?
Last edited by falsam on Wed Jan 07, 2026 12:37 pm, edited 1 time in total.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
falsam
Enthusiast
Enthusiast
Posts: 644
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by falsam »

I simplified the code:
- Removed the JavaScript,
- Removed the callback.

Code: Select all

EnableExplicit

Enumeration
  #app
  #webview
EndEnumeration

; HTML Code
Define Html.s = ~"<!DOCTYPE html>\n" +
                ~"<html>\n" +
                ~"<body>\n" +
                ~"\n" +
                ~"<label>First name:</label><br>\n" +
                ~"<input type=\"text\" id=\"fname\"><br>\n" +
                ~"<label>Last name:</label><br>\n" +
                ~"<input type=\"text\" id=\"lname\"><br><br>\n" +
                ~"<input type=\"submit\" id=\"submit\" value=\"Submit\">\n" +
                ~"</body>\n" +
                ~"</html>\n"

; Event
Define Event

OpenWindow(#app, 100, 100, 400, 400, "Simple Form", #PB_Window_SystemMenu)

; Webview option debug (view console)
WebViewGadget(#webview, 0, 0, 400, 400, #PB_WebView_Debug)

; Insert code HTML
SetGadgetItemText(#webview, #PB_WebView_HtmlCode, Html)

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

The issue with the Tab key persists.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
infratec
Always Here
Always Here
Posts: 7767
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by infratec »

Hm ...
if you reach the submit button and use the mouse to select the first input again and the use tab again it works without any problems.

The question is: what is selected if you press the tab key when the button is selected.
In a normal browser it jumps into the browser menu.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 644
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by falsam »

Hello Infratec,
The Tab key allows you to navigate from one input field to another. You can click on the submit button to validate the form. If the user presses the Tab key again to return to the first input field, the application freezes.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
JHPJHP
Addict
Addict
Posts: 2285
Joined: Sat Oct 09, 2010 3:47 am

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by JHPJHP »

Hi falsam,

I can confirm what you're seeing.
• Windows 11 Pro, 25H2
• PureBasic 6.30 beta 6 (x86/x64)

I tested it across multiple projects, from the simplest to my latest, which include some advanced scripts, and the results were the same.

Great catch, especially right before the final 6.30 version is set to be released.

Note: I have a simple JavaScript patch that can work around the problem, though it will most likely be fixed before it’s needed.
breeze4me
Enthusiast
Enthusiast
Posts: 648
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by breeze4me »

This appears to be a bug in WebView2 itself and does not seem to have been fully resolved yet.
https://github.com/MicrosoftEdge/WebVie ... issues/589
After investigation, it appears to be halting during the execution of the internal GetNextDlgTabItem function.

The following workaround seems to be working.
Tested on Windows 10.

Code: Select all

EnableExplicit

Enumeration
  #app
  #webview
EndEnumeration

; HTML Code
Define Html.s = ~"<!DOCTYPE html>\n" +
                ~"<html>\n" +
                ~"<body>\n" +
                ~"\n" +
                ~"<label>First name:</label><br>\n" +
                ~"<input type=\"text\" id=\"fname\"><br>\n" +
                ~"<label>Last name:</label><br>\n" +
                ~"<input type=\"text\" id=\"lname\"><br><br>\n" +
                ~"<input type=\"submit\" id=\"submit\" value=\"Submit\">\n" +
                ~"</body>\n" +
                ~"</html>\n"

; Event
Define Event

OpenWindow(#app, 100, 100, 400, 400, "Simple Form", #PB_Window_SystemMenu)

; Webview option debug (view console)
WebViewGadget(#webview, 0, 0, 400, 400, #PB_WebView_Debug)

SetWindowLongPtr_(GadgetID(#webview), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#webview), #GWL_STYLE) | #WS_TABSTOP)

; Insert code HTML
SetGadgetItemText(#webview, #PB_WebView_HtmlCode, Html)

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

JHPJHP
Addict
Addict
Posts: 2285
Joined: Sat Oct 09, 2010 3:47 am

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by JHPJHP »

Hi breeze4me,

Windows 11 Pro, 25H2
PureBasic 6.30 beta 6 (x86/x64)

I have tested this with multiple examples, and the behavior is consistent. The only caveat is that when the WebViewGadget is placed inside a container, #WS_TABSTOP must be applied to the container rather than the WebViewGadget.
breeze4me
Enthusiast
Enthusiast
Posts: 648
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by breeze4me »

@JHPJHP
Thank you for the test.
Hmm, a container gadget shouldn't have that flag, so we need a more reliable solution.

Edit:
Another workaround.
It seems that the WS_EX_CONTROLPARENT style should be applied to all container-type gadgets, and the WebViewGadget itself. (probably the Edge WebGadget too, but excluding panel gadgets)
The combination of the GetAncestor and GetNextDlgTabItem functions called within the WebView2 control seems to be the cause.

ContainerGadget, CanvasGadget, FrameGadget, ScrollAreaGadget.

Code: Select all

EnableExplicit

Enumeration
  #app
  #webview
EndEnumeration

; HTML Code
Define Html.s = ~"<!DOCTYPE html>\n" +
                ~"<html>\n" +
                ~"<body>\n" +
                ~"\n" +
                ~"<label>First name:</label><br>\n" +
                ~"<input type=\"text\" id=\"fname\"><br>\n" +
                ~"<label>Last name:</label><br>\n" +
                ~"<input type=\"text\" id=\"lname\"><br><br>\n" +
                ~"<input type=\"submit\" id=\"submit\" value=\"Submit\">\n" +
                ~"</body>\n" +
                ~"</html>\n"

; Event
Define Event

OpenWindow(#app, 100, 100, 500, 400, "Simple Form", #PB_Window_SystemMenu)

ContainerGadget(10, 0, 0, 400, 400)
SetWindowLongPtr_(GadgetID(10), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(10), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)
  
  CanvasGadget(11, 0, 0, 400, 400, #PB_Canvas_Container)
  SetWindowLongPtr_(GadgetID(11), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(11), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)
    
    FrameGadget(12, 0, 0, 400, 400, "frame", #PB_Frame_Container)
    SetWindowLongPtr_(GadgetID(12), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(12), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)
      
      ScrollAreaGadget(13, 0, 0, 400, 400, 600, 600)
      SetWindowLongPtr_(GadgetID(13), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(13), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)
        
        WebViewGadget(#webview, 0, 0, 400, 400, #PB_WebView_Debug)
        SetWindowLongPtr_(GadgetID(#webview), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(#webview), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)
        ;SetWindowLongPtr_(GadgetID(#webview), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#webview), #GWL_STYLE) | #WS_TABSTOP)
        
      CloseGadgetList()
    CloseGadgetList()
  CloseGadgetList()
CloseGadgetList()

; Insert code HTML
SetGadgetItemText(#webview, #PB_WebView_HtmlCode, Html)

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
SplitterGadget.

Code: Select all

EnableExplicit

Enumeration
  #app
EndEnumeration

; HTML Code
Define Html.s = ~"<!DOCTYPE html>\n" +
                ~"<html>\n" +
                ~"<body>\n" +
                ~"\n" +
                ~"<label>First name:</label><br>\n" +
                ~"<input type=\"text\" id=\"fname\"><br>\n" +
                ~"<label>Last name:</label><br>\n" +
                ~"<input type=\"text\" id=\"lname\"><br><br>\n" +
                ~"<input type=\"submit\" id=\"submit\" value=\"Submit\">\n" +
                ~"</body>\n" +
                ~"</html>\n"

; Event
Define Event

OpenWindow(#app, 100, 100, 500, 400, "Simple Form", #PB_Window_SystemMenu)

WebViewGadget(1, 0, 0, 400, 400, #PB_WebView_Debug)
SetWindowLongPtr_(GadgetID(1), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(1), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

WebViewGadget(2, 0, 0, 400, 400, #PB_WebView_Debug)
SetWindowLongPtr_(GadgetID(2), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(2), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

SplitterGadget(0, 100, 0, 400, 400, 1, 2, #PB_Splitter_Vertical)
SetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

; Insert code HTML
SetGadgetItemText(1, #PB_WebView_HtmlCode, Html)
SetGadgetItemText(2, #PB_WebView_HtmlCode, Html)

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

Code: Select all

EnableExplicit

Enumeration
  #app
  #webview
EndEnumeration

; HTML Code
Define Html.s = ~"<!DOCTYPE html>\n" +
                ~"<html>\n" +
                ~"<body>\n" +
                ~"\n" +
                ~"<label>First name:</label><br>\n" +
                ~"<input type=\"text\" id=\"fname\"><br>\n" +
                ~"<label>Last name:</label><br>\n" +
                ~"<input type=\"text\" id=\"lname\"><br><br>\n" +
                ~"<input type=\"submit\" id=\"submit\" value=\"Submit\">\n" +
                ~"</body>\n" +
                ~"</html>\n"

; Event
Define Event

OpenWindow(#app, 100, 100, 500, 400, "Simple Form", #PB_Window_SystemMenu)

; ButtonGadget(#PB_Any, 0, 0, 50, 20, "")

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

; The behavior of the two styles below is slightly different.

; SetWindowLongPtr_(GadgetID(#webview), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#webview), #GWL_STYLE) | #WS_TABSTOP)
SetWindowLongPtr_(GadgetID(#webview), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(#webview), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

; Insert code HTML
SetGadgetItemText(#webview, #PB_WebView_HtmlCode, Html)

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
User avatar
falsam
Enthusiast
Enthusiast
Posts: 644
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by falsam »

Thank you for your help. Using SetWindowLongPtr_ as suggested by breeze4me solves my current issue. I hope this Tab key bug will be fixed soon. I will continue to explore this new WebGadget.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
falsam
Enthusiast
Enthusiast
Posts: 644
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: PB 6.30 WebViewGadget & Tab Key freeze

Post by falsam »

Resolved with PureBasic 6.30 beta 7. Thanks, Fred 👍

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Post Reply