admin管理员组

文章数量:1291135

Typically an app is opened from chrome://apps/ or in the button Chrome apps, but how would from an external Chrome Extension?

My extension:

->manifest.json
->background.js

My app:

->manifest.json
->background.js

Then, how to launch my app from my extension?

Typically an app is opened from chrome://apps/ or in the button Chrome apps, but how would from an external Chrome Extension?

My extension:

->manifest.json
->background.js

My app:

->manifest.json
->background.js

Then, how to launch my app from my extension?

Share Improve this question edited Jun 13, 2014 at 6:59 Xan 77.6k18 gold badges197 silver badges217 bronze badges asked Jun 13, 2014 at 5:30 Walter Chapilliquen - wZVanGWalter Chapilliquen - wZVanG 12k8 gold badges44 silver badges64 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

If you own both items you can just use messaging to open the app window when receiving a message from the extension. This does not have a permissions warning that will repel users like management. https://developer.chrome./extensions/messaging

First, add this to both manifests:

"externally_connectable": { "ids": [ "idoftheotheritem" ] }

Then, listen for messages in your app and create a app window:

chrome.runtime.onMessageExternal.addListener(function() {
  chrome.app.window.create("app.html");
}

Finally, send from the extension:

chrome.runtime.sendMessage("idoftheapp", { launch: true })

It's in the docs: chrome.management.launchApp

chrome.management.launchApp("YourAppsId", function(){
  if(chrome.runtime.lastError) console.error(chrome.runtime.lastError);
  else console.log("App launched");
});

You will need the "management" permission for that.


Edit: see Daniel Herr's answer for a less invasive solution.

本文标签: javascriptHow to launch a Chrome App from a Chrome ExtensionStack Overflow