我有background.js:
var responses = {}
var filter = {
urls: ["http://*/*", "https://*/*"],
types: ["main_frame"]
}
var options = ["responseHeaders"]
chrome.webRequest.onHeadersReceived.addListener(function(details) {
responses[details.url] = details
}, filter, options)
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
sendResponse({
headers: responses[sender.tab.url]
})
})
ScriptForParsing.js
var markup;
var cookies;
var headers;
$(document).ready(function() {
parse();
});
function parse() {
markup = document.documentElement.innerHTML;
cookies = document.cookie;
document.addEventListener('GetHeaders', function(event) {
chrome.runtime.sendMessage(chrome.runtime.id, {}, {}, function(response) {
document.dispatchEvent(new CustomEvent("GotHeaders",{
detail: response.headers
}))
})
})
}
我希望我的var标头类似于response.headers-怎么样?