는 devtool.js 위해 나는이 같은 일회성 메시지를 듣고 있어요 :Chrome 확장 프로그램 : devtools 패널에서 일회성 메시지를 수신 할 수 있습니까? 내 코드에서
chrome.devtools.panels.create("TT's Automatron", "devtool/icon.ico", "devtool/panel.html",
function(panel) {
var panelconsole;
panel.onShown.addListener(function tmp(panel) {
panel.onShown.removeListener(tmp);
panelconsole = panel;
// this works
chrome.runtime.sendMessage({type:'get-status'}, function(response) {
panelconsole.write_queue(response.globalstatus);
});;
// this does not work - cannot listen to the same messages from popup.js
// as I do it in background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
alert();
});
});
}
);
을 코드에서 내가 한 번 메시지를 보낼 수 있지만 한 번 메시지를들을 수 없습니다. Alert()
은 메시지를 보내더라도 절대로 트리거되지 않습니다. 배경 스크립트에서 나는 문제없이 메시지를 chrome.runtime.onMessage.addListener()
으로들을 수 있습니다. 그렇다면 왜 devtools에 없습니까?
나는 documentation을 읽었지 만 표시되는 일회성 메시지는 수신되지 않으며 세션 연결 만 수신합니다. 그것은 가능하지 않다는 것을 의미합니까? 배경 스크립트에서
나도 같은 메시지를 듣고 오전이 작동 :
메시지
// listening to the same messages as in devtools panel
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
alert('This works');
switch(request.type) {
// recognising different messages
case "start-tron":
// ..some code..
sendResponse({globalstatus: globalstatus});
break;
}
});
이
팝업에서 오는 스크립트 :
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.runtime.sendMessage({type: "start-tron", tabid:tabs[0].id});
});
은 어쩌면 내가 배경 및 DevTools로 사이에 오픈 수명이 긴 세션 연결도 있다는 것을 언급해야한다 :
var port = chrome.runtime.connect({name: 'automatron_console'});
port.onMessage.addListener(function(item) {
// if reference exists - panel is open
if (panelconsole) {
panelconsole.write_log(item);
}
});
그래서 DevTools로의 팝업에서 메시지를들을 수없는 이유. js는 백그라운드에서 수행합니다 .js?
documentation에서
이 alert'이 차단 될 수 있습니다'적절한 디버깅을 사용 : 첫 번째 (세 점 설정 아이콘에서 도크 측 = "부동")를 DevTools로 분리, Ctrl-Shift-I를 눌러 devtools-for-devtools를 호출하면 수동으로 중단 점을 설정하거나 코드에서'debugger' 문을 사용할 수 있습니다. – wOxxOm
나는 몇개의 중단 점에 앉아 있었지만 아무것도하지 않았다. 스크립트는 중단없이 실행되고, devtools-for-devtools에서는 아무것도 보이지 않는다. 단지 중단 점이다. – Incredible
달성하고자하는 것을 볼 수 있도록 배경 페이지 스크립트를 게시물에 추가 할 수 있습니까? –