Creating a Minimal Chrome App
Chrome apps are zip files that contain all the assets you’d usually expect in
a web application. They contain HTML files, JavaScript files, images, videos,
and so on. In addition, each zip archive contains two special files:
manifest.json
and
background.js
.
manifest.json
describes the Chrome app’s metadata and typically looks like this:
ChromeApps/SimpleApp/manifest.json
{
"manifest_version": 2,
"name": "My First Chrome App",
"version": "1",
"permissions": ["serial"],
"app": {
"background": {
"scripts": ["background.js"]
}
}
}
It uses JavaScript Object Notation (JSON)
4
and supports a lot of different
options.
5
Only
name
and
version
are mandatory. They specify the app’s name and version.
These attributes will appear in the Chrome Web Store, if you decide to make
your application available to the public. So choose them carefully if you’re
going to release your application.
manifest_version
contains the version of the manifest file’s specification. Currently,
you must set it to 2 for Chrome apps.
With the
permissions
option, your Chrome app can request permissions that
applications do not have by default. We set it to
serial
so the Chrome app is
allowed to access the computer’s serial port. Users who install a Chrome app
have to agree to all permissions it requests.
Eventually,
manifest.json
sets the Chrome app’s background page to a file named
background.js
. Which brings us to the second mandatory file in each Chrome
app:
background.js
.
Not only does every Chrome app need a starting point, but every app also
needs some kind of lifecycle management. Like operating systems control a
4.
http://json.org/
5.
https://developer.chrome.com/apps/manifest
report erratum • discuss
Creating a Minimal Chrome App • 269
www.it-ebooks.info