私は本当に奇妙なバグを経験しています。
私の background.js ファイルには、そのようにタブを閉じる関数があります
closeTabs = function(tabIds,category){
for(var i=0; i<tabIds.length;i++){
var url = findTabById(tabIds[i]).url;
console.log(url);
reservedUrls.push(url);
}
console.log(arrToString(reservedUrls));
if(tabIds.length>0){
chrome.tabs.remove(tabIds,function(){
});
}
}
この関数は、ブラウザ アクションから呼び出されます。
次に、タブの削除イベントのイベント リスナーを作成します。
chrome.tabs.onRemoved.addListener(function(tabId){
console.log('removed');
var removedUrl = findTabById(tabId).url;
console.log(removedUrl);
console.log(arrToString(reservedUrls));
var index = reservedUrls.indexOf(removedUrl);
if(index>-1){
console.log('in here');
reservedUrls.splice(index,1);
} else {
var category = findCategoryById(tabId);
if(category){
for(var i=0;i<currentTabs[category];i++){
if(currentTabs[category][i].id==tabId){
currentTabs[category].splice(i,1);
}
}
} else {
for(var i=0;i<ungrouped.length;i++){
if(ungrouped[i].id==tabId){
ungrouped.splice(i,1);
}
}
}
console.log('sending message');
chrome.runtime.sendMessage({type:'removed',tabId:tabId});
}
console.log(currentTabs);
});
タブが最初の関数によって閉じられると、それらを reservedUrls に配置して、ロジックが異なる動作をするようにします。バックグラウンドページのコンソールを見ると、当然のようにif文が入っています。ただし、ポップアップのコンソールでは、else ステートメントに移動したことがログに記録されます。
誰もがこの格差を経験していますか。もしそうなら、典型的な原因は何ですか?