Page 1 of 1

[ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Posted: Mon Jun 10, 2024 6:13 pm
by skinkairewalker
Worked in PureBasic 6.10 LTS

If you include both a WebGadget and WebViewGadget the program will freeze when initializing the second Gadget; see below.
NOTE: Two WebGadget's or two WebViewGadget's work without an issue;


Does Not Work:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  WebGadget(0, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
  WebViewGadget(1, 400, 0, 400, 400)
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf


Does Work:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  WebGadget(0, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
  WebGadget(1, 400, 0, 400, 400, "", #PB_Web_Edge)
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf


Does Work:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  WebViewGadget(0, 0, 0, 400, 400)
  WebViewGadget(1, 400, 0, 400, 400)
  SetGadgetText(0, "https://www.purebasic.com")
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Posted: Mon Jun 10, 2024 7:29 pm
by zikitrake
But this works fine :shock:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  
  WebViewGadget(0, 400, 0, 400, 400)
  SetGadgetText(0, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
  WebGadget(1, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Posted: Tue Jun 11, 2024 5:07 pm
by breeze4me
In 6.11 beta 3, an internal command was added to change the cache folder of the WebView2 control using an environment variable(https://www.purebasic.fr/english/viewto ... 78#p621678 , Windows: [Done] WebView Gadget leaves files on hard drive), and there seems to be a conflict with this.
If you find and remove the "WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS" string from the compiled executable, it will run properly. This string is in Unicode format.

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Posted: Tue Jun 11, 2024 7:25 pm
by Fred
So we can't share the cache between instances ? That's annoying.

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Posted: Wed Jun 12, 2024 9:27 am
by breeze4me
After investigating, it seems that the problem is caused by setting the environment variable value only in WebViewGadget and not in WebGadget.
Setting the value before the WebGadget as shown below solves the problem.

However, Paul's bug report is for the user data folder, so it can't be set in an environment variable.
A folder with the same name as the executable that is created in the Users/AppData/Roaming folder will not be removed by changing the cache folder.
You must change the userDataFolder string in the following two functions to prevent the new folder from being created in the Users/AppData/Roaming folder.

Code: Select all

CreateWebViewEnvironmentWithOptionsInternal(bool checkRunningInstance, int runtimeType, PCWSTR userDataFolder, IUnknown * environmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * webViewEnvironmentCreatedHandler)
CreateCoreWebView2EnvironmentWithOptions(PCWSTR browserExecutableFolder, PCWSTR userDataFolder, ICoreWebView2EnvironmentOptions * environmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * environmentCreatedHandler)

Code: Select all

SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", ~"--disk-cache-dir=\"" + GetTemporaryDirectory() + ~"\\WebView2_Cache\"")

; --disk-cache-dir="C:\temp\\WebView2_Cache"

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  
  WebGadget(0, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
  
  WebViewGadget(1, 400, 0, 400, 400)
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf