WebView, WebEngine CORS headers and file loading in SFOS >= 4.4

@flypig had given me a heads up for the more restrictive CORS rules as of 4.4. To keep it to the point, to load local resources in a WebView:

    WebView {
        /* This will probably be required from 4.4 on. */
        Component.onCompleted: {
           /* disable ALL
            WebEngineSettings.setPreference("security.disable_cors_checks", true, WebEngineSettings.BoolPref) 
            OR */
            WebEngineSettings.setPreference("security.fileuri.strict_origin_policy", false, WebEngineSettings.BoolPref)
        }
        id: webView
        anchors.fill: parent
        url: "../mah/index.html"
    }

WebEngineSettings requires
import Sailfish.WebEngine 1.0

4 Likes

This should go to the documentation as well

And I should finally get to forking the sailfish wiki :slight_smile:

related: Bug - Documentation is not a tree but a forest

1 Like

Ah, yes! And as you point out the Community news piece from @flypig should become documentation!

Let’s write this down to the Browser | Sailfish OS Documentation or Working with Browser | Sailfish OS Documentation as well. Thank you @poetaster .

1 Like

I think it belongs here:

I’ll make a PR as soon as I get around to it…!

Correct and actually I have already written short paragraph there: “Loading and using local resources”. Certainly improvement PRs are welcome.

2 Likes

This PR updates the docs with some more detail about the different potential approaches (including referencing your nice Python example @poetaster).

Any comments or suggestions for improving it would be appreciated.

1 Like

Er, ‘my’ nice python example was cribbed from @martyone 's python example (which happened to implement a thread model) and is, of course, mostly your code :slight_smile: and props to @nephros !

I’ve always admired you clear and comprehensive deep dives in the newsletters and have benefited from them, a great deal. I’m just really happy if I’ve contributed to that! Thanks!

2 Likes