2012-07-03 3 views
0

그래서 다른 크롬 확장과 통신해야하는 Chrome 확장 프로그램을 만들고 있습니다. 많은 모순 된 정보가 있으면 아무런 결과가 없습니다. 지금까지 사용하고있는 코드는 다음과 같습니다.크롬 확장 프로그램에서 다른 크롬 확장 프로그램으로 메시지를 보내는 방법은 무엇입니까?

확장의 HTML 중 하나에 참여 (options.html) 다른 확장의 background.html에서

console.log("sending message..."); 
chrome.extension.sendRequest(receivingExtensionID, {txt: "sometext"}, function (res){ 
     console.log("response received"); 
     console.log("res: " + res); 
     try{ 
     console.log("res.txt: " + res.txt); 
     }catch(e){ 
     console.log("ERROR: cannot print res.txt because res is undefined."); 
     } 
}); 

console.log("message sent.") 

수신 부분

chrome.extension.onRequestExternal.addListener(function(request, sender, sendResponse) { 
    sendResponse({txt: "someothertext"}); 
}); 

나는 다음과 같은 오류가 발생합니다 :

Port error: Could not establish connection. Receiving end does not exist. 
디버거에 오류를 클릭하면 내가 세부-것을 제외하고는 다른 무슨 말을 모르는

이 말한다 : 나는 sendMessage 첨부 및 onMessageExternal와 함께 동일한 코드를 시도

chromeHidden.Port.dispatchOnDisconnect 

나는

+0

첫 번째 확장 전에 두 번째 확장을로드 했습니까? –

+0

그래, 이거 믿을 수가 없어! 내가 반대 순서로 그들을로드하고 즉시 일했습니다! 감사합니다 ~~! – DeadlyBacon

+0

수락 할 수 있도록 답변을 게시해야합니까, 아니면 (겉으로는 사소한) 질문을 삭제 하시겠습니까? –

답변

0

첫 번째 확장 (메시지를 보내는)를 수신 두 번째 연장 (후 로드되어야 도와주세요 동일한 결과를 얻을 수 메시지). 이것은 분명합니다. 역순으로로드 될 때 발신자는 수신자가 생성되기 전에 메시지를 보냅니다.

관련 문제