javascript - Chrome Apps, FileSystem API: chooseEntry method isn't working -



javascript - Chrome Apps, FileSystem API: chooseEntry method isn't working -

edit: found error, can't solve it, see below.

manifest.json { ... "offline_enabled": true, "app": { "background": { "persistent": true, "scripts": [ "/js/background.js" ] } }, "permissions": [ "notifications", "storage", {"filesystem": ["directory"]} ] } background.js chrome.app.runtime.onlaunched.addlistener(function() { window.open('/index.html'); }); index.html <!doctype html> <html> <head> <title>achshar player</title> <script src="/js/index.js"></script> </head> <body> <input id="input" type="button"> </body> </html> index.js window.addeventlistener('load', function() { document.getelementbyid('input').addeventlistener('click', function() { chrome.filesystem.chooseentry({type: 'openfile'}, function(readonlyentry) { console.log(readonlyentry); }); }); });

the method called , callback, file choosing dialogue never comes , readonlyentry undefined when callback executed. no errors on dev tools, on 35.0.1916.153 m.

i have tried different variations of manifest declarations filesystem since function not undefined in script execution, manifest unlikely issue.

when utilize official example extension of filesystem api app works, chrome setup isn't problem either. problem seem code, lost here.

edit: added each file's content

edit 2: found error, how solve it?

i tried in canary , realize errors shown via chrome.runtime.lasterror , not normal console. , error get.

invalid calling page. function can't called background page.

but not in background.js, in index.js called index.html.

i tried in chrome, , there doesn't seem wrong code you've posted. suspect there problem way loading javascript, or perchance context running in (foreground page vs. background page)

for instance, if javascript code snippet in main.js, run in background page, , window , document elements won't ones main page.

my test app looks similar yours, except have left out main.js file manifest, , have constructed little index.html file, loads foreground.js script instead. finish app:

manifest.json { "manifest_version": 2, "name": "stack overflow question test app", "version": "1", "offline_enabled": true, "app": { "background": { "persistent": true, "scripts": [ "/js/background.js" ] } }, "permissions": [ "notifications", "storage", {"filesystem": ["directory"]} ] } js/background.js chrome.app.runtime.onlaunched.addlistener(function() { chrome.app.window.create("index.html"); }); index.html <!doctype html> <html> <head> <title>test</title> <script src="js/foreground.js"></script> </head> <body> <input id="input" /> </body> </html> js/foreground.js window.addeventlistener('load', function() { document.getelementbyid('input').addeventlistener('click', function() { chrome.filesystem.chooseentry({type: 'openfile'}, function(readonlyentry) { console.log(readonlyentry); }); }); });

when run this, can click on input element, , see file picker. choosing entry returns fileentry object, logged console (of foreground page, not background page. right-click in app window , select "inspect element", rather "inspect background page", see foreground console.):

fileentry {filesystem: domfilesystem, fullpath: "/testfile.rtf", name: "testfile.rtf", isdirectory: false, isfile: true…} foreground.js:4 note:

from original code, appeared using framework jquery search dom elements within page. chrome apps work fine jquery, have aware of when using raw dom node object, , when have wrapped jquery object.

specifically, line

$('input').addeventlistener('click', function() {

would have caused problems.

replacing with

document.queryselector('input').addeventlistener('click'), function() {

would correctly find element on page, , attached click handler it.

javascript google-chrome google-chrome-app

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -