簡體   English   中英

如何從Chrome擴展程序啟動Chrome應用程序?

[英]How to launch a Chrome App from a Chrome Extension?

通常,應用程序是從chrome:// apps /按鈕Chrome應用程序中打開的,但是外部Chrome擴展程序會如何?

我的擴展名:

->manifest.json
->background.js

我的應用:

->manifest.json
->background.js

那么, 如何從我的擴展程序啟動我的應用程序

如果您擁有這兩個項目,則只需使用消息傳遞即可在從擴展程序接收消息時打開應用程序窗口。 這沒有權限警告會拒絕用戶管理。 https://developer.chrome.com/extensions/messaging

首先,將其添加到兩個清單中:

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

然后,在應用中收聽消息並創建應用窗口:

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

最后,從擴展發送:

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

它位於文檔中: chrome.management.launchApp

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

您將需要"management"權限。


編輯:請參閱Daniel Herr關於微創解決方案的答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM