콘텐츠 스크립트와 배경 스크립트가있는 Chrome 플러그인을 작성 중이며 둘을 통신하려고합니다. 내 콘텐츠 스크립트에서 chrome.runtime.sendMessage가 예상대로 작동하지 않습니다.
, 내가chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
console.log(response.farewell);
});
내 배경 스크립트에서
를하고있는 중이 야,이 같은chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
}
);
내 매니페스트 외모
을하고있는 중이 야 :{
"manifest_version": 2,
"name": "Tesing Phase",
"version": "1.0",
"background": {
"persistent": false,
"scripts": ["bgscript.js"]
},
"content_scripts": [{
"js": ["contentscript.js"],
"all_frames": true,
"run_at" : "document_start",
"matches": ["*://*/*"]
}],
"web_accessible_resources": ["script.js"]
}
때 I을 플러그인을 실행하면 다음 오류가 발생합니다.
Uncaught TypeError: Object #<Object> has no method 'sendMessage'
chrome.runtime
로깅을 시도했지만 아무런 방법도 없었습니다 sendMessage
. 저는 우분투에서 Chromium의 버전 25.0을 사용하고 있습니다. 나는 sendRequest
을 사용해 보았지만 감가 상각되었고 sendMessage
을 사용해야한다고했습니다.
누구나 내가 여기에없는 것을 지적 할 수 있습니까? 이 작업에 필요한 권한이 있습니까? 25 chrome.extension.sendMessage
을 사용 - 당신은 크롬 20와 호환되는 확장을 작성하려는 경우
감사하십시오
chrome.runtime
개체에 대한 방법은 다음과 같은 방법 대신을 사용할 수 있습니다 k google chrome dev 페이지에이 정보가 없습니다. –이 방법은 훌륭하게 보이지만이 방법론은 여전히 최대 31 개의 크롬 버전에 유효합니까? 또는 적응해야 할 것인가? 그리고 오래된 deprecated 메시지 전달 메소드가 Chrome – user280109
@ user280109의 최신 버전에서 완전히 삭제되었는지는 알 수 없습니다. 여전히 유효합니다. 호환성 레이어없이 'chrome.runtime.'을 사용할 수도 있지만, Google의 자동 업데이트 프로그램 덕분에 더 이상 Chrome 25를 사용하지 않습니다. –