12

I need to use the fileSystem permission in the manifest.js, so I can read/write files from my Chrome extension.

When I load my extension with the "Load unpacked extension" button, Chrome displays:

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

So for Chrome my extension is a legacy packaged app.

My question is how to technically convert a "legacy packaged app" into a "packaged apps" so I can test the fileSystem API ?

Here is my manifest:

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

Indeed I'm already using "manifest_version": 2.

Rob W
  • 341,306
  • 83
  • 791
  • 678
Stephaneuh
  • 123
  • 1
  • 1
  • 4

2 Answers2

15

Packaged apps have a different structure in the "app" section of the manifest. Your manifest.json would be something like:

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

and you would also need a background script ("main.js" in this sample) that opens your index.html when the user clicks on the app icon:

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('index.html', {
    bounds: {
      width: 500,
      height: 300
    }
  });
});
kenjiru
  • 780
  • 6
  • 11
mangini
  • 4,179
  • 2
  • 19
  • 23
  • 13
    Google is definitely not making it easy for developpers to produce apps: confusion between extensions, hosted apps and packaged apps, limited permissions etc. – Augustin Riedinger Nov 26 '14 at 15:41
  • 3
    If I change the extension to an app, then I get `'tabs' is only allowed for extensions and legacy packaged apps, but this is a packaged app.`, now what? Is it even possible to require both the `tabs` and the `filesystem` permissions? – Tony Bogdanov Feb 13 '16 at 17:07
  • 2
    @AugustinRiedinger, Google really screwed this one up now. They should have just invented one thing instead of inventing four: extensions, hosted apps, packaged apps, PPAPI. – Pacerier Aug 18 '16 at 10:58
  • That's plain braindead. I'm trying to dump URLs from my browsing history into a file (too long for a data URI) for several hours. If I make my code into a packaged app, it complains that `history` can be used from extensions and legacy apps only. This has a smell of two extensions that talk to each other. – polkovnikov.ph Oct 16 '16 at 00:50
  • I believe this api is only available as a legacy API by now – matanster Jan 27 '19 at 19:19
  • @TonyBogdanov did you figure out a solution? I'm looking for the same thing. – Rodrigo Ruiz Jul 01 '20 at 03:54
  • @RodrigoRuiz I'm sorry but I don't remember, this was 7 years ago, but my best guess is I either gave up, or rethought my entire structure / idea. – Tony Bogdanov Jul 02 '20 at 04:32
-2

Add this to your manifest:

"manifest_version": 2,
Ahi Tuna
  • 1,253
  • 2
  • 14
  • 26