Google Chrome 'onLaunched' error in plugin - google-chrome

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?

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.

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",
...
}

You can follow the Chromium Development Calender here.

Related

Why does it show "Visit Website" and not Add extension?

I would like publish a website (web app) on our intranet as chrome app in the google web store.
I want to publish this app to all Computers in my domain, I've seen that I can do this with the GPO of Google and it works with every extension but not with mine.
So the problem I ran into is that if I publish my app in the chrome web store you can't download it. It only says "Visit Website". As shown in the picture here: Visit Website Button in the web store
This is how my manifest.json looks like:
{
"manifest_version": 2,
"name": "Support-Ticket",
"version": "1.0",
"icons": {
"128": "128.png"
},
"app": {
"urls": [
"https://intranet.*.com/example"
],
"launch": {
"web_url": "https://intranet.*.com/example"
}
},
"permissions": [
"notifications"
]
}
I've tested it with another little app where the manifest looks like this:
{
"name": "Support Test",
"version": "1.0",
"icons": {
"128":"128.png"
},
"manifest_version": 2,
"browser_action": {},
"permissions":[
"tabs"
],
"background":{
"scripts": ["background.js"],
"persistent": false
}
}
And the .js like this:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function(tab) {
// Tab opened.
});
});
I would like to have this website as chrome app and than install it on all computers in my domain with a shortcut in the Start Menu or Desktop.
Update:
I managed to create the app and display the intranet on the app with the html tag "webview".
Now it looks like this:
Window Frame
Does anyone know how I can change the color of the window frame to a darker grey?

Error loading extension

I got this extension for google chrome and it won't load when I try to load unpacked extension. Where is the problem?
{
"manifest_version": 2,
"name": "HTML",
"description": "HTML change",
"version": "1",
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": ["https://ocjene.skole.hr/pocetna/prijava/*"],
}
],
}
Trailing commas mean invalid json - try this change first:
{
"manifest_version": 2,
"name": "HTML",
"description": "HTML change",
"version": "1",
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": ["https://ocjene.skole.hr/pocetna/prijava/*"]
}
]
}
You may refer with this Can't load unpacked extension? forum.
I'm going to recommend that you start with a powerwash. This will wipe your device and return it to factory settings (and also put you back to the stable channel). Full instructions can be found in this help center article.
After the powerwash, I would suggest that you test whether or not the extension will load while still running a stable build. If it does, and then it stops working when you switch o the dev channel, that helps to narrow down the issue.
Additional references:
Load Unpacked Extension
Unable to load unpacked extensions

Using chrome.runtime.sendmessage to communicate from a webpage to a packaged app

I'm trying to communicate from a web page to a packaged app. The idea is to have the web page read a number from a serial device. Because I want to access the serial device, I need a packaged app and can't use an extension. This is pretty similar to Keep Chrome Packaged App running in background? and it seems that Chrome documentation says this is possible.
How can I execute the chrome.runtime.sendMessage from a regular web page? When I do so, I get *Uncaught TypeError: Cannot read property 'sendMessage' of undefined. My simple function is:
function doFunction(){
chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
function(response) {
if (!response.success)
handleError(url);
});
}
My packaged app loads and can access the serial ports. But my suspicion is the manifest isn't "enabling" the chrome.runtime of the regular webpage. Manifest.json:
{
"name": "Hello World!",
"description": "My first Chrome App.",
"version": "0.1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": { "16": "calculator-16.png", "128": "calculator-128.png" },
"permissions": [
"serial",
"*://localhost/*"
],
"externally_connectable": {
"matches": [
"*://localhost/*"]
}
}
Maybe it's the ://localhost/ which I'm using for testing. But Chrome does not complain.
Any ideas out there? Thanks in advance.
Xan's comment did the trick.
While Chrome did not complain about *://localhost/*, it did not work. Chrome did complain about other combinations such as file://localhost/.
I added foo.com to host file and then served up my web page through a web server, and it worked! I can communicate from my web page to my packaged app.
Note that browsing to file://www.foo.com/hostpage.html did not work. But browing to http://www.foo.com:3000/hostpage.html did. (I'm using Rails, hence the 3000 port).
Morale of the story: When testing locally, you need to add an entry with a bogus second level domain to your host file.
Here's my manifest.json:
{
"name": "RFID Tag Reader",
"description": "Reads RFID Tags connected via USB reader",
"version": "0.0.0.1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": {
"16": "rfid-16.png",
"128": "rfid-128.png"
},
"permissions": [
"serial",
"*://www.foo.com/*",
"*://arealsite.net/*"
],
"externally_connectable": {
"matches": [
"*://www.foo.com/*",
"*://arealsite.net/*"
]
}
}
Adding "*://localhost/*" to externally_connectable worked for me.

Chrome extension with no icon?

I am trying to create a simple Google Chrome extension. I don't want it to have an icon next to the omnibar. Is this possible? What do I need to put in my manifest.json?
Yes, this is possible. To do it, just don't declare browser_action in your manifest. Remember, though, to get it to work, you'll need to do something to run the script. contextMenus are a great way to do that.
Here's a manifest that has no browser action line, so it will not display an icon:
manifest.json
{
"manifest_version": 2,
"description": "Example",
"name":"Example",
"icons": {
"16": "img16.png" }, // Needed for the context menu
"background": {
"scripts":["background.js"] },
"permissions":[ "tabs", "contextMenus" ], // contextMenus permission allows you to create the action
"version": "1.0"
}

Getting error: "This webpage is not available" for my chrome app's options page

My CRX had the proper html page options.html in it, the manifest declares it properly (it shows up as a link on the chrome://extensions page) but when I click that link, Chrome gives the error:
This webpage is not available
The webpage at chrome-extension://invalid/ might be temporarily down or it may have moved permanently to a new web address.
It says "invalid" but the app runs perfectly well (all the content scripts run, the background created a database and saved to it). Why would it show as invalid? Why doesn't it have the extensions' id?
Here's the manifest:
{
"manifest_version": 2,
"name": "MyAPP",
"description": "My App",
"version": "0.0.0.32",
"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/background.js"
]
}
},
"permissions":
[
"unlimitedStorage",
"fullscreen",
{
"fileSystem":
[
"write"
]
},
"background",
"<all_urls>",
"tabs"
]
}
Does it need to be declared in "web_accessible_resources"? Any idea what's wrong?
Update
Adding to "web_accessible_resources" does not fix the issue. I added everything on that page too.
update 2
It looks like it might be a Chrome bug for packaged apps. When I remove the "app" section in the manifest, it works! This is a bug since the Chrome app documentation states that apps can have options pages: https://developer.chrome.com/apps/options.html
Options pages are only supported for extensions, you have indeed discovered a documentation bug (I've filed issue 255079).