WebKitGtk doesn't load local files

523 Views Asked by At

I've tried loading a local html file using webkit_web_view_load_uri() with a file:// URL. However, the webview would display a blank page. To circumvent this, I tried using webkit_web_view_load_html() and it worked correctly.

Now that I'm trying to load some images in the html using the <img> tag, the images aren't loaded (It displays a blank page).

I'm puzzled because I tried before (~ 2 months ago) a similar method and it worked.

Note: I copied the contents of the generated HTML into a file and loaded it with Firefox and it worked as it should (The images are visible), but with another WebKitGtk application I had lying around the images didn't load.

Note: I'm using C++ as the main programming language (I'd prefer having C++ types in the solutions only if possible)

Note: I have set webkit_settings_set_allow_file_access_from_file_urls() and webkit_settings_set_allow_universal_access_from_file_urls() to TRUE

2

There are 2 best solutions below

1
On BEST ANSWER

Ok, I've managed to solve this. The solution had NOTHING to do with webkitgtk, which is strange. It seems that the application was trying to download the page instead of loading it. This traces to a faulty MIME type database.

Tl;Dr:

Execute this:

rm ~/.local/share/mime/packages/user-extension-html.xml
update-mime-database ~/.local/share/mime

and use webkit_web_view_load_uri() instead of webkit_web_view_load_html() with a file:// URI

0
On

I had the same problem in C. You have to explicitly set file:// as base_uri when you call webkit_web_view_load_html().

See also answer here