Cordova: Launching chrome with --allow-file-access-from-files from VS 2017

怎甘沉沦 提交于 2019-12-07 07:01:33

问题


I'm working on a cordova application in Visual Studio 2017 and I'm trying to access the filesystem using the file plugin. Unfortunately this does not work when debugging the application using 'Simulate in browser' (using cordova-simulate).

A 'SecurityError: It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.' error is raised.

I guess if have to pass '--allow-file-access-from-files' option to chrome, but I don't know how to do this, because chrome is launched automatically in a new window and I cannot find any configuration options in Visual Studio.


回答1:


Some Chrome Quirks are:

  • Chrome filesystem is not immediately ready after device ready event. As a workaround you can subscribe to filePluginIsReady event. Example: javascript window.addEventListener('filePluginIsReady', function(){ console.log('File plugin is ready');}, false); You can use window.isFilePluginReadyRaised function to check whether event was already raised.
  • window.requestFileSystem TEMPORARY and PERSISTENT filesystem quotas are not limited in Chrome.
  • To increase persistent storage in Chrome you need to call window.initPersistentFileSystem method. Persistent storage quota is 5 MB by default.
  • Chrome requires --allow-file-access-from-files run argument to support API via file:/// protocol.
  • File object will be not changed if you use flag {create:true} when getting an existing Entry.

Form above quirks use basic steps here:

At the time of writing this article, Google Chrome has the only working implementation of the FileSystem API. A dedicated browser UI does not yet exist for file/quota management. To store data on the user's system, may require your app to request quota. However, for testing, Chrome can be run with the --unlimited-quota-for-files flag. Furthermore, if you're building an app or extension for the Chrome Web Store, the unlimitedStorage manifest file permission can be used in place of requesting quota. Eventually, users will receive a permission dialog to grant, deny, or increase storage for an app.

You may need the --allow-file-access-from-files flag if you're debugging your app from file://. Not using these flags will result in a SECURITY_ERR or QUOTA_EXCEEDED_ERR FileError.



来源:https://stackoverflow.com/questions/47154220/cordova-launching-chrome-with-allow-file-access-from-files-from-vs-2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!