framework7io / framework7

Full featured HTML framework for building iOS & Android apps
http://framework7.io
MIT License
17.97k stars 3.24k forks source link

Routes.js error with Fetch and file:// in url when linked file is stored on local android storage file:///data/user/0/my.app/files/files #4249

Closed goedzo closed 4 months ago

goedzo commented 4 months ago

Describe the bug

I run my cordova app from internal storage file:///android_asset/index.html linking (via routes.js) locally downloaded files onto my storage which is file:///data/user/0/my.app/files/files/*.html

In the version 7 this worked without issue, but with version 8, the usage of Fetch() now gives the error when Framework7 is loading the new routes from file:///data/user/0/my.app/files/files/

The exact error shown in the console is:

Fetch API cannot load file:///data/user/0/my.app/files/files/pages/log.html URL scheme "file" is not supported

I now use a workaround to update the routes.js in code where I point to a version stored online, but you can imagine this is not a good solution. In case anyone needs this workaround, here is the actual code that solves this issue:

routes.forEach(function (aRoute){
            if(aRoute.url) {
                if(aRoute.url.includes('/pages/')) {
                    if (app_android) {
                        //Fetch does not allow file://
                        var tRouteUrl=aRoute.url.replace('/pages/','pages/');
                        var tNewUrl=server + '/' + tRouteUrl;
                        console.log('Updating route -- ' + aRoute.url +' -- to '+tNewUrl );
                        aRoute.url=tNewUrl;
                    }
                }
            }
            if(aRoute.componentUrl) {
                if(aRoute.componentUrl.includes('/pages/')) {
                    if (app_android) {
                        //Fetch does not allow file://
                        var tRouteUrl=aRoute.componentUrl.replace('/pages/','pages/');
                        var tNewUrl=server + '/' + tRouteUrl;
                        console.log('Updating route -- ' + aRoute.componentUrl +' -- to '+tNewUrl );
                        aRoute.componentUrl=tNewUrl;
                    }
                }
            }
        }); 
    }

Expected behavior

I expect that routes.js is able to use files that are stored locally with file:// links.

Actual Behavior

API Exception with Fetch()

nolimits4web commented 4 months ago

That is not F7's issue, you can: