簡體   English   中英

需要將消息從Chrome打包應用發送到網頁

[英]Need to send a message from Chrome Packaged App to a web page

我需要將消息從chrome打包的應用程序發送到應用程序外部的網頁。 我可以使用以下命令將網頁中的消息發送到打包的應用程序

chrome.runtime.sendMessage(extID,toSend, function(response) {
   console.log("messag sent to " + extID);
   if(response){
    console.log(response.received);
   }
   else {
   console.log("no reply");
   };
});

我可以從打包的應用中獲得回復。 沒問題。 但是我需要繼續將應用程序中的信息發送到頁面,而不是單次回復。

我嘗試在應用程序端使用此代碼:

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  chrome.tabs.sendMessage(tabs[0].id, msg, function(response) {
  console.log(response.farewell);
  });
  });
}

但它無法將chrome.tabs識別為有效對象。 當我在manifest.json的權限部分添加“ tabs”時,它告訴我打包應用程序不支持tabs權限。

那么,除了從頁面本身發送的消息的簡單響應之外,還有什么方法可以將消息從Chrome打包的應用程序發送到外部網頁?

您需要在清單externally_connectable中包含要從其發送的網站域,並且需要使用chrome.runtime.onMessageExternal或chrome.runtime.onConnectExternal這是文檔中的全部內容

暫無
暫無

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

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