Google Chrome 'onLaunched' error in plugin
-
04-07-2021 - |
题
I am following the google chrome web app development on http://developer.chrome.com/trunk/apps/first_app.html and the web app is not launching. when i click on the app icon on the page it closes the tab. I have downloaded the sample apps and plugins from github but they too are not working when i look at the console i get this error, please not i have enabled experimental API's in chrome://flags.
Uncaught TypeError: Cannot read property 'onLaunched' of undefined
I have updated my chrome browser to version 22.0.1229.79. My manifest.json file is
{
"name": "Hello World!",
"description": "My first packaged app.",
"manifest_version": 2,
"version": "0.1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": {
"16": "calculator-16.png",
"128": "calculator-128.png"
}
}
And my background.js file
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html', {
'width': 400,
'height': 500
});
});
Can someone point me where am going wrong?
解决方案
Get a dev/beta copy of Chrome that is at least version 23.
I also had to add the following line to the manifest.json file before I could get the sample to run
{
...,
"minimum_chrome_version": "23",
...
}
其他提示
This error also occurs if you leave out the "app": {}
declaration in the manifest.json.
I.e. "background": { "scripts": [ "background.js" ] },
Will give this error.
And "app": { "background": { scripts": ["background.js"] },
will work properly.
The new-style packaged apps (with the background
key in the app
section in the manifest) are only supported in Chrome 23 (currently in the dev channel, soon to be in the beta channel) and later.
You can follow the Chromium Development Calender here.