我正在尝试编写一个扩展,将所有http标头信息存储在一个数组中,以便我可以通过弹出窗口显示它。为了保持一个整洁的弹出页面,我需要在每次新加载后清除标题,但我需要一种方法来告诉它何时应该发生。
1)清除新的requestId
2)在最后一次onComplete发生后,在webRequest之前清除
有什么建议吗?这是我到目前为止所做的(选项2)......如果你只使用main_frame但这并不理想,它会有用。
beforeRedirect = function( details ) {
if (debug && details.tabId > 0 && typeof(tabs[details.tabId]) != 'undefined') {
//returns all info stored in tabs array for the current tab
log('The following data was recorded and stored', tabs[details.tabId]);
}
//adds current tab to tabs array and stores header info in there
var tabId = details.tabId;
var url = details.url;
details.type = 'normal';
//if tab is null... init
if (typeof(tabs[details.tabId]) == 'undefined') {
tabs[tabId] = {};
tabs[tabId].isRedirect = false;
}
//set Header info
tabs[tabId].lasactive = new Date().getTime();
if (typeof(details.redirectUrl) != 'undefined') {
tabs[tabId].isRedirect = true;
details.type = 'redirect';
}
if (typeof(tabs[tabId].requestId) == 'undefined' || tabs[tabId].completed) {
tabs[tabId].requestId = details.requestId;
log('clearing tab['+tabId+'] headers');
tabs[tabId].requestHeader = []; //init or reset
}
tabs[tabId].requestHeader.push(details);
log('Saved tab '+tabId+'\'s '+details.type+' header information', details);
return;
}
completed = function( details ) {
if (debug && details.tabId > 0 && typeof(tabs[details.tabId]) != 'undefined') {
//returns all info stored in tabs array for the current tab
log('The following data was recorded and stored', tabs[details.tabId]);
}
//adds current tab to tabs array and stores header info in there
var tabId = details.tabId;
var url = details.url;
details.type = 'normal';
//if tab is null... init
if (typeof(tabs[details.tabId]) == 'undefined') {
tabs[tabId] = {};
tabs[tabId].isRedirect = false;
}
//set Header info
tabs[tabId].lasactive = new Date().getTime();
if (typeof(details.redirectUrl) != 'undefined') {
tabs[tabId].isRedirect = true;
details.type = 'redirect';
}
if (typeof(tabs[tabId].requestId) == 'undefined' || tabs[tabId].completed) {
log('clearing tab['+tabId+'] headers');
tabs[tabId].requestId = details.requestId;
tabs[tabId].requestHeader = []; //init or reset
}
tabs[tabId].requestHeader.push(details);
tabs[tabId].completed = true;
log('Saved tab '+tabId+'\'s '+details.type+' header information', details);
return;
}