'fileSystem'仅适用于打包的应用程序,这是一个传统的打包应用程序

时间:2013-04-23 14:05:29

标签: google-chrome google-chrome-extension google-chrome-app

我需要在manifest.js中使用fileSystem权限,这样我才能从Chrome扩展程序中读/写文件。

当我使用"加载解压缩的扩展程序"加载我的扩展程序时按钮,Chrome显示:

'fileSystem' is only allowed for packaged apps, and this is a legacy packaged app.

因此,对于Chrome,我的扩展程序是旧版打包应用

我的问题是如何在技术上转换" 旧版打包应用"进入" 打包应用"所以我可以测试fileSystem API吗?

这是我的清单:

{
 "name": "MyApp",
 "version": "1.0",
 "manifest_version": 2,
  "app": {
  "launch": {
  "local_path": "index.html"
  }
 },
 "icons": {
 "128": "favicon.ico"
 },
  "permissions" : [
    "fileSystem"
  ]
}

确实,我已经在使用"manifest_version": 2

2 个答案:

答案 0 :(得分:12)

打包的应用在清单的“app”部分中具有不同的结构。你的manifest.json会是这样的:

{
  "name": "MyApp",
  "version": "1.0",
  "manifest_version": 2,
  "app": {
    "background": {
      "scripts": [
        "main.js"
      ]
    }
  },
  "icons": {
    "128": "favicon.ico"
  },
  "permissions": [
    "fileSystem"
  ]
}

并且您还需要一个后台脚本(此示例中为“main.js”),当用户点击应用图标时会打开您的index.html:

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('index.html', {
    bounds: {
      width: 500,
      height: 300
    }
  });
});

答案 1 :(得分:-2)

将此添加到您的清单:

"manifest_version": 2,
相关问题