Webkit HTMLViewer.LoadPage and Local Images

Using Webkit for HTMLViewer in Mac/Windows. The issue we’re having is that we write a graphics files to a temporary location, generate some html and use the LoadPage method to display it. On macOS we had to use the declare that Sam created to get around the CEF security.

I have tried using relative paths as well and absolute URL paths and our images do not load. We cannot use the native renderer for other reasons that are too long to get into now.

I am getting nothing in the CancelLoad or Error events. It just refuses to load the local images.

Is there a trick to getting these images to load? Can we tell the HTMLViewer to load local images?

Hi @Bob_Keeney2,

how about including the graphics as Base64 in the HTML file? Then they would not have to be loaded externally. A disadvantage is of course that this has an effect on the size of the HTML file.

Greetings

Not having any trouble in app I’m working on. HTML and images are in the same directory; images are referenced just by name. They are in .png format. Maybe start with everything in the same directory (no paths) and see if it works, then start moving things around.

are you using the latest version of xojo? the failure appears only on mac or also on windows? have you tried opening the generated file from google chrome?

I was also thinking using an external browser and use its error reporting to diagnose.

To further clarify this happens only:

When passing in the HTML string via LoadPage. So like this:

    //Method A
    dim refFile as Folderitem
    dim html as string = kSomeHTML
    HTMLViewer1.LoadPage( html, refFile )

If I write the HTML to disk and then load it it like this:

    //Method B
    dim htmlFile as FolderItem = GetFolderItem( "test.html")
    HTMLViewer1.LoadPage( htmlfile )

It works as expected. So there’s something special about Method A that has changed in 2021 R1 since this worked in prior versions.

1 Like

Method B also fires the CancelLoad event in Windows (not tested on MacOS)

We talked about this not too long ago on a thread that’s around here somewhere. I resorted to importing the images as BASE64 when embedding for my use case of loading HTML via LoadPage. It did work at one point with your Method A above, but the security in the recent CEF update broke that I believe.

Did a quick test with the following code in a button in both 2019 R3.2 and 2021R1.1:

dim refFile as Folderitem
dim html as string = "<!DOCTYPE html><html><head><title>Test</title></head><body><img src=""test.png""></body></html>"

refFile = SpecialFolder.Desktop

HTMLViewer1.LoadPage( html, refFile )

Works in 2019, fails in 2021. Same machine, everything else the same.

Yeah, that’s the CEF version difference. The new version disallows a lot of things that used to work for the sake of security. In this case it’s local file access.

I found the previous thread you mentioned; it said that refFile had to be an html (extension, at least) file… which I just tried, but still did’t work.

In an email conversation with William he said this is a new CEF security thing and it should not be used anymore if you accessing local files. Write the HTML to disk and load the page using the FolderItem. Apparently since the HTML file is local it’s okay to access other local files. He also said LoadPage( string, folder item) will (probably) go away.

2 Likes

We may add more functions for our Chromium Plugin classes.
Like some options to set.