PB 6.30B2 SetGadgetItemText has length limit with WebViewGadget

Post bugreports for the Windows version here
Seymour Clufley
Addict
Addict
Posts: 1266
Joined: Wed Feb 28, 2007 9:13 am
Location: London

PB 6.30B2 SetGadgetItemText has length limit with WebViewGadget

Post by Seymour Clufley »

There seems to be a length limit, so that trying to load a very long HTML string doesn't work. You can tell this because the HTML onload event (an alert box) doesn't occur.

This bug can be worked around by saving the HTML to file and loading that in the gadget using SetGadgetText, but still.

This bug was also present with PB6.2, and probably before that.

Code: Select all

Macro ImageAsPNGDataURI(img,var,pngdepth)
  UsePNGImageEncoder()
  *mem = EncodeImage(img,#PB_ImagePlugin_PNG,0,pngdepth)
  var = "data:image/png;base64,"+Base64Encoder(*mem,MemorySize(*mem))
  FreeMemory(*mem)
EndMacro


Procedure.s WVG_LoadHTML(html.s)
  
  Static win.i
  Static wg.i
  
  If wg=0
    ww=1600 : wh=1200
    win = OpenWindow(#PB_Any,0,0,ww,wh, "WebViewGadget")
    wg = WebViewGadget(#PB_Any,0,0,ww,wh)
  EndIf
  
  SetWindowTitle(win,"HTML length: "+Str(Len(html)))
  SetGadgetItemText(wg,#PB_WebView_HtmlCode,html)
  
EndProcedure




; this will work
h.s = "<body onload="+Chr(34)+"alert('loaded 1')"+Chr(34)+"></body>"
WVG_LoadHTML(h)
For a = 1 To 100 : WaitWindowEvent(50) : Next a



; this will not work
iw = 1200
ih = 1000
img.i = CreateImage(#PB_Any,iw,ih,32)
StartDrawing(ImageOutput(img))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For a = 1 To 1000
  bx = Random(iw)
  by = Random(ih)
  bw = Random(50,10)
  bh = Random(50,10)
  Box(bx,by,bw,bh,RGBA(Random(255),Random(255),Random(255),Random(255)))
Next a
For x = 0 To iw-1
  For y = 0 To ih-1
    Plot(x,y,RGBA(0,0,0,Random(128)))
  Next y
Next x
StopDrawing()
ImageAsPNGDataURI(img,du.s,32)
FreeImage(img)

h.s = "<body onload="+Chr(34)+"alert('loaded 2')"+Chr(34)+"><img src='"+du+"' /></body>"
du="" ; free memory
WVG_LoadHTML(h)

Repeat
  WaitWindowEvent(50)
Until GetAsyncKeyState_(#VK_ESCAPE)
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Fred
Administrator
Administrator
Posts: 18298
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 6.30B2 SetGadgetItemText has length limit with WebViewGadget

Post by Fred »

You're right, it's a limitation of the WebView2 NavigateToString() function as you can see here: https://learn.microsoft.com/en-us/dotne ... .0.3405.78

"The htmlContent parameter may not be larger than 2 MB (2 * 1024 * 1024 bytes) in total size. The origin of the new page is about:blank."

As the content is converted to wide string, it's more than 2MB and fail. I will add a debugger check to limit the string size to 1000000 chars, it should be fine.

The recommanded way for big page is to write it on disk first.
Post Reply