1

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 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This seems to have affected many people recently on Arch. Ulauncher got many bug reports out of the blue for our Preferences view (built with WebkitGTK). We changed the implementation to registering a custom scheme with register_uri_scheme and then serving the files with the correct mimetypes (ignoring the local mimetypes) from the callback.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.