Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cordova-plugin-file in Chrome: cordova is not defined

I use cordova-plugin-file in my ionic app to download images and save to local.

When I run it in emulator or iphone, there is no error, but when I test it in Chrome, it says, cordova is not defined when I try to access cordova.file.dataDirectory

How can I run cordova-plugin-file in chrome?

like image 793
Sato Avatar asked Jul 12 '15 12:07

Sato


People also ask

How to use InAppBrowser in cordova?

function openBrowser() { var url = 'https://cordova.apache.org'; var target = '_blank'; var options = "location = yes" var ref = cordova. InAppBrowser. open(url, target, options); ref. addEventListener('loadstart', loadstartCallback); ref.

Which are the two main files to be edited in Cordova?

By default, your app has permission to write to cordova. file. applicationStorageDirectory and cordova. file.

What is Cdvfile?

A cdv-file path is a specific formatted file path that will be resolved into a native file path automatically. A cdv-file path looks like this: cdvfile://localhost/fs-root/path/to/file. Where fs-root is one of the different file system roots that exists in a mobile device.

What permissions does the Cordova plugin need to write?

By default, your app has permission to write to cordova.file.applicationStorageDirectory and cordova.file.externalApplicationStorageDirectory, and the plugin doesn't request permission for these two directories unless external storage is not mounted.

Why is my Cordova file being deleted by the OS?

The OS may delete these files when the device runs low on storage, nevertheless, apps should not rely on the OS to delete files in here. ( iOS, Android, BlackBerry 10, OSX, windows) cordova.file.externalApplicationStorageDirectory - Application space on external storage. ( Android)

Can I store files in the root directory in Cordova?

cordova.file.applicationStorageDirectory is read-only; attempting to store files within the root directory will fail. Use one of the other cordova.file.* properties defined for iOS (only applicationDirectory and applicationStorageDirectory are read-only). The encoding parameter is not supported, and UTF-8 encoding is always in effect.

What files should be synced with Cordova?

cordova.file.syncedDataDirectory - Holds app-specific files that should be synced (e.g. to iCloud). ( iOS, windows) cordova.file.documentsDirectory - Files private to the app, but that are meaningful to other application (e.g. Office files). Note that for OSX this is the user's ~/Documents directory. ( iOS, OSX)


1 Answers

Cordova will not be available in the browser; only on your device.

In your index.html you should have this script reference:

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

As the note says, the script won't be available during the development. It will be replaced during the build process.

You can try it yourself:

cordova platform add android

then

cordova build

and you should find under platforms\android\assets\www 2 js files: cordova.js and cordova_plugins.js.

Another option is to add browser as platform:

cordova platform add browser

and the run it:

cordova run browser

but you might face a few troubles.

like image 189
LeftyX Avatar answered Oct 08 '22 16:10

LeftyX