2

The background permission is very important. Without it, how do you create the window?

chrome.app.window.create(...)

I have an app with the following manifest:

{
    "manifest_version": 2,
    "name": "MyApp",
    "description": "MyApp",
    "version": "0.7",
    "minimum_chrome_version": "27",
    "offline_enabled": true,
    "options_page": "options.html",
    "icons": 
    {
        "16": "images/icon16.png",
        "48": "images/icon48.png",
        "128": "images/icon128.png"
    },
    "app": 
    {
        "background": 
        {
            "scripts": 
            [
                "scripts/messaging.js",
                "scripts/utils.js",
                "scripts/database.js",
                "scripts/fs.js",
                "scripts/background.js"
            ]
        }
    },
    "permissions": 
    [
        "unlimitedStorage",
        "fullscreen",
                {
            "fileSystem": 
            [
                "write"
            ]
        },
        "background",
        "<all_urls>"
    ],
    "update_url": "http://192.168.1.101/chrome/crx/updates/MyApp2.xml"
}

This app shows as full screen. The database and file handling, as well as the creating of the user's window is all handled by background.js which runs in the background. In a regular Chrome App when I've tried to add some of those functions (for example, chrome.app.window.create(...) which is what creates the client window), the runtime has thrown an error saying those functions/objects don't exist in the front end. So, without background permission, how do I do those things?

Don Rhummy
  • 24,730
  • 42
  • 175
  • 330

2 Answers2

4

First, some naming clarifications:

I believe your question is: "I have a Chrome App which runs on Desktop Chrome, and it uses the "background" and "fullscreen" permissions. When I use cca to create a port for Mobile, cca complains that the permissions are not recognized."

Well, the good news is that all cca apps are always "fullscreen" and "background". The warning message is just because v2 Chrome Packaged Apps don't require those permissions, and so we missed adding them to our whitelist of accepted permissions.

The warnings, in this case, are safe to ignore (though I'm not sure if there exists a fullscreen API, that likely won't work). Those warnings are useful when you require a permission we really do not support yet, say, like "bluetooth".

So I guess my question is: did you try moving on to the next step to see if it worked?

Edit: With the latest release of cca to npm (v 0.0.11) we should not show warnings if your app requests these permissions.

mmocny
  • 8,775
  • 7
  • 40
  • 50
  • thank you. I did move to the next step and opened it in eclipse but my emulator stated having issues. I'll try again tomorrow. so, do I need to remove all my fullscreen code? – Don Rhummy May 07 '14 at 03:08
  • If the api's don't exist you will get runtime errors, which depending on your application, may be a problem. You probably don't want to remove the fullscreen code since you expect to use it on desktop, just use feature-detection to skip the fullscreen calls on mobile. (Also, let me know which APIs you are using and we can consider writing polyfills for mobile). – mmocny May 07 '14 at 17:20
  • Sorry for the delay, I will compile a list of the APIs and let you know. – Don Rhummy May 09 '14 at 01:40
  • I tried to run it in the ios simulator and all I get is a big white screen. I can't figure out how to get debugging/error messages. How can I find what's wrong? – Don Rhummy May 09 '14 at 03:04
  • 1
    White screen usually means syntax errors or startup exceptions before your `chrome.app.window.create` call completes. Likely you have errors in your background scripts, or maybe there is a problem with `cca`.You can diagnose those [using safari remote inspector](http://moduscreate.com/enable-remote-web-inspector-in-ios-6/) and then typing `chrome.runtime.reload()` into the console. If `chrome` api's aren't registered yet (i.e. the error was really early in the bootstrap), you can try just `location.reload()`. Then, debug your issues until they go away! – mmocny May 09 '14 at 13:38
  • Thank you that helps! Any idea about breakpoints? Do `console.log()` statements print there? One weird bug: XCode is telling me that my app (due to the included cordova library) won't build for iPad Retina 64 bit, only the 32 bit. Any idea if this is due to settings with Chrome's tool? (P.S. I haven't forgotten that I owe you the APIs I'm using) – Don Rhummy May 12 '14 at 04:30
  • Here are the APIs I'm using that I believe are relevant: `webkitRequestFullScreen()`, `chrome.runtime.getBackgroundPage()`, `chrome.app.window.current().focus()`,`chrome.runtime.sendMessage()`, `chrome.runtime.onInstalled.addListener()`, `chrome.app.runtime.onLaunched.addListener()`, `chrome.app.window.create()`, `chrome.runtime.onMessage.addListener()`, `AppWindow..moveTo()`, `AppWindow.resizeTo()` – Don Rhummy May 12 '14 at 22:26
  • Thanks for the list, can track here: https://github.com/MobileChromeApps/mobile-chrome-apps/issues/161 – mmocny May 13 '14 at 14:28
  • Regarding debugging: my recommendation is to learn to use remote web inspector, which works on iOS 6+ and Android 4.4+. The instructions are different for each platform but easy to Google for. If you want console messages printed in XCode, you can also install the org.apache.cordova.console plugin with `cca plugin add org.apache.cordova.console`. – mmocny May 13 '14 at 14:30
  • thank you for helping! I'll follow that bug report. (apologies for asking more questions...) do you also know why it's not compiling for ipad 64 bit? it says the error is with the Cordova lib – Don Rhummy May 13 '14 at 14:40
2

The background permission you're asking for in your permissions is a different background permission to the one you mean, which doesn't need any permission at all.

-> To let you background page get loaded by chrome, so that your app can handle events, doesn't need a permission. This is something all apps can do.

-> To make your app force chrome to run all the time is something hosted apps and legacy packaged apps can do. We are working on making this available to all packaged apps as well, but for now they can't. This requires the 'background' permission. I don't think you want or need this.

So I'd say your error is something else. Can you provide your scripts/background.js file?

Ben Wells
  • 1,896
  • 13
  • 9