[英]Google Chrome: How to determine which window has generated WebRequest?
我写了chome扩展名,该扩展名处理浏览器中的所有请求:
manifest.json的:
{
"name": "MyExtension",
"version": "0.1",
"description": "All requests are under control!",
"permissions": [
"tabs",
"webRequest",
"http://*/*"
],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
background.js:
chrome.webRequest.onCompleted.addListener(
function(details) {
console.log(details);
console.log(chrome.tabs.getCurrent());
},
{urls: ["http://*/*"],
types: ["image"]});
但是现在,我想知道是哪个页面(选项卡?)创建了此请求?
例如:
Request 1 - generated by google.com page,
Request 2 - generated by stackoverflow.com.
我该如何解决这个任务?
以下代码将获取tab \\ page详细信息谁生成了Web请求。
onCompleted Listener
具有一个tabId属性,该属性标识标签,并且您可以检索该标签的所有详细信息。
chrome.webRequest.onCompleted.addListener(
function (details) {
chrome.tabs.get(details.tabId, function (tab) {
console.log("This " + JSON.stringify(details) + " Web request is from this " + tab.id + " tab and its details are" + JSON.stringify(tab));
});
}, {
urls: ["http://*/*"],
types: ["image"]
});
This {"frameId":0,"fromCache":true,"ip":"74.125.236.63","method":"GET","parentFrameId":-1,"requestId":"563","statusCode":200,"statusLine":"HTTP/1.1 200 OK","tabId":64,"timeStamp":1359389270317.956,"type":"image","url":"http://www.google.co.in/images/srpr/logo3w.png"} Web request is from this 64 tab and its details are{"active":true,"highlighted":true,"id":64,"incognito":false,"index":4,"pinned":false,"selected":true,"status":"loading","title":"Google","url":"http://www.google.co.in/","windowId":1}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.