8
나는 팝업에서 사용자가 버튼을 누르면 링크 된 프로필 페이지에서 데이터를 추출해야하는 확장 프로그램을 개발 중입니다. 나는 popup.js 페이지에서 contentscript로 메시지를 전달하고 응답으로 나는 linkedin 프로필 페이지에서 contentscript로 추출한 데이터를 popup.html에 표시 할 것이다. 하지만 나는 popup.html을 검사 할 때 오류가 발생합니다. 오류 :크롬 확장 메시지를 팝업에서 콘텐츠 스크립트로 보내기
참고로Port: Could not establish connection. Receiving end does not exist. lastError:29
Error in event handler for 'undefined': Cannot read property 'farewell' of undefined
TypeError: Cannot read property 'farewell' of undefined
at chrome-extension://kdfgoafjicddfffdbfofdmckejemfije/popup.js:6:25
at <error: illegal access>
at Event.dispatchToListener (event_bindings:356:21)
at Event.dispatch_ (event_bindings:342:27)
at Event.dispatch (event_bindings:362:17)
at Object.chromeHidden.Port.dispatchOnDisconnect (miscellaneous_bindings:258:27)
, 내 매니페스트 파일은 다음과 같습니다
{
"name": "SoftwareGrid",
"version": "0.5",
"icons": { "16": "icons/16.png","48": "icons/48.png", "128": "icons/128.png" },
"description": "Shows user cresidentials on Linkedin",
"permissions": [
"cookies",
"tabs",
"http://www.linkedin.com/*"
],
"browser_action": {
"default_title": "Show Profile",
"default_icon": { "16": "icons/16.png","48": "icons/48.png", "128": "icons/128.png" },
"default_popup": "popup.html"
},
"background": {
"scripts": ["jquery-1.7.2.min.js","background.js"]
},
"content_scripts": [{
"matches": ["http://www.linkedin.com/*"],
"all_frames": true,
"js": ["jquery-1.7.2.min.js", "script.js"],
"run_at": "document_end"
}],
"web_accessible_resources": [
"icons/i1.png"
],
"manifest_version": 2
}
내 popup.js 파일 :
function sendClicks() {
console.log("popup.js > sendClicks()");
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
console.log("avra' inviato?");
}
$(function() {
console.log("popup.js > OMD Extension ready");
$('#sendclicks').click(function(){
sendClicks();
});
});
내 contentscript 파일
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"});
});
Plz help!
. 어쩌면 디버그 오류가 발생하여 탭을 변경했을 수 있습니까? 'chrome.tabs.query ({active : true, currentWindow : true}, ... '를 사용하고 있다면 디버깅하는 동안이 탭을 열고 활성화해야합니다. 그렇지 않으면'script.js'의 리스너가 호출되지 않습니다. –
도움을 주셔서 감사합니다. 그러나 내 콘텐츠 스크립트에 오류가있어서 바보 같았습니다. – saadsaf
콘텐츠 스크립트의 오류는 무엇입니까? 대답으로 올바른 파일을 넣을 수 있습니까? – makenova