我正在为谷歌浏览器写一个扩展。内容脚本从不会看到sendNextProfile请求已从后台页面发送。至少,RECEIVED REQUEST FOR NEXT PROFILE不会出现在控制台日志中,并且背景中不会看到新的请求。谷歌铬扩展消息背景到上下文
该处从内容SCRIPT
//send request for first profile
var currentProfile=0;
chrome.extension.sendRequest({cmd: "openProfile", url: profileLinks[currentProfile]});
//listen for request to send next profile
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if(request.cmd == "sendNextProfile") {
console.log("RECEIVED REQUEST FOR NEXT PROFILE");
++currentProfile;
chrome.extension.sendRequest({cmd: "openProfile", url: profileLinks[currentProfile]});
}
});
此处的代码从背景PAGE
//detect when message tab is closed and request new profile
//var closedTabId=null;
chrome.tabs.onRemoved.addListener(function(tabid, removeInfo) {
console.log("TAB CLOSED "+tabid);
if (tabid==msgTabId) {
chrome.extension.sendRequest({cmd: "sendNextProfile"});
console.log("REQUESTED NEW PROFILE");
}
});
在背景侧的代码中,出现在控制台消息作为预期的,所以会出现的请求发送。那么这个代码是怎么回事?
'在背景方面,控制台消息按预期显示。' 什么消息完全显示? TAB CLOSED或请求新的配置文件或两者兼而有之? – Achshar