Chrome applications, file system API: selectEntry method does not work

Edit: an error was found, but cannot 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 is called, as well as the callback, but the file selection dialog never arrives, and readOnlyEntryis undefined when the callback is executed. There are no errors in dev tools, I am on 35.0.1916.153 m.

I tried different variants of manifest declarations for fileSystem, but since the function is not undefined in the script execution, the manifest is unlikely to be a problem.

When I use the official example fileSystem API extension , the application works, so setting up Chrome is also not a problem. The problem seems to be in my code, but I got lost here.

:

2: , ?

, chrome.runtime.lastError, . , .

. .

background.js, index.js, index.html.

0
1

Chrome, , , - , . , , javascript , , , ( ).

, JavaScript main.js, , window document .

, , main.js , index.html, foreground.js script. :

manifest.json

{
    "manifest_version": 2,
    "name": "Qaru 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);
        });
    });
});

, , . FileEntry, ( , ). " ", " ", .):

FileEntry {filesystem: DOMFileSystem, fullPath: "/TestFile.rtf", name: "TestFile.rtf", isDirectory: false, isFile: true…} foreground.js:4

:

, jQuery DOM . Chrome Apps jQuery, , DOM Node, jQuery.

,

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

.

document.querySelector('input').addEventListener('click'), function() {

.

+2

All Articles