我正在尝试编写一个扩展,将所有 http 标头信息存储在一个数组中,以便我可以通过弹出窗口显示它。为了保持一个整洁的弹出页面,我需要在每次新加载后清除标题,但我需要一种方法来判断何时应该发生这种情况。
1)清除新的requestId
- 不起作用,因为 requestId 每次都会更改
2) 在最后一次 onComplete 发生后的 webRequest 之前清除
- 不起作用,因为每个图像、main_frame 等都以 onComplete 结尾,因此它会在每个图像或页面完成后清除
有什么建议么?这是我到目前为止所拥有的(选项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;
}