PB6.20 - WebViewGadget - WaitWindowEvent() can not be called from a 'binded' event callback?
Posted: Fri Feb 14, 2025 11:56 am
Hi. How do I work around this limitation to prevent this error message?
Test code:
Error:
Test code:
Code: Select all
Html$ = ~"<button id=\"displayInfo\">Display Info</button>\n"+
~"<script>\n"+
~" const displayInfoElement=document.getElementById(\"displayInfo\");\n"+
~" document.addEventListener(\"DOMContentLoaded\", () => {\n"+
~" displayInfoElement.addEventListener(\"click\", () => {\n"+
~" window.displayInfo(1000, 2000).then(result => {\n"+
~" displayInfoElement.textContent = result.sum;\n"+
~" });\n"+
~" });\n"+
~" });\n"+
~"</script>";
Procedure.s showInputRequester(question.s, preFill.s = "", isPasswort.b = #False)
Protected width.i = 350, height.i = 150, gap.i = 5
Protected result.s = ""
Protected win.i = OpenWindow(#PB_Any, 0, 0, width.i, height.i, "Question", #PB_Window_Tool | #PB_Window_ScreenCentered)
AddKeyboardShortcut(win.i, #PB_Shortcut_Return, 10)
AddKeyboardShortcut(win.i, #PB_Shortcut_Escape, 99)
Protected flag.i = 0
If isPasswort.b = #True
flag.i = #PB_String_Password
EndIf
Protected cGad.i = TextGadget(#PB_Any, gap.i, gap.i, width - gap.i*2, height - 50 - gap.i*2, question.s)
Protected sGad.i = StringGadget(#PB_Any, gap.i, height - 50, width - gap.i*2, 20, preFill.s, flag.i)
Protected bGad.i = ButtonGadget(#PB_Any, width / 2 - 20, height - 25, 40, 20, "OK")
SetActiveGadget(sGad.i)
Protected quit.i = #False
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
quit.i = #True
Case #PB_Event_Menu
Select EventMenu()
Case 10
result.s = GetGadgetText(sGad.i)
quit.i = #True
Case 99
quit.i = #True
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case (bGad.i)
result = GetGadgetText(sGad.i)
quit.i = #True
EndSelect
EndSelect
Until quit.i
RemoveKeyboardShortcut(win.i, #PB_Shortcut_All)
CloseWindow(win.i)
ProcedureReturn result.s
EndProcedure
Procedure IncrementJS(JsonParameters$)
Dim Parameters(0)
ParseJSON(0, JsonParameters$)
ExtractJSONArray(JSONValue(0), Parameters())
; call some value from the user for processing
Protected test.s = showInputRequester("Please enter a value")
ProcedureReturn UTF8(~"{ \"sum\": "+Str(Parameters(0) + Parameters(1))+ "}")
EndProcedure
OpenWindow(0, 100, 100, 400, 400, "Hello", #PB_Window_SystemMenu)
WebViewGadget(0, 0, 0, 400, 400)
SetGadgetItemText(0, #PB_WebView_HtmlCode, Html$)
BindWebViewCallback(0, "displayInfo", @IncrementJS())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Code: Select all
[11:51:31] [ERROR] Line: 33
[11:51:31] [ERROR] WaitWindowEvent(): WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback.