为什么OnBeforeRequest函数不起作用

问题描述

我正在编写浏览器扩展程序,并且我用于OnBeforeRequest的代码无法分析网络流量。我找不到我在做什么。您能帮忙解决一下还是突出显示错误?谢谢。

//content.js
var contentString = "";
chrome.webRequest.onBeforeRequest.addListener(function (details) {
      var tabid = details.tabId;      
      var sourceurl = "N/A";
      if (tabid >= 0) {
          chrome.tabs.get(parseInt(tabid),function (tab) {
              sourceurl = tab.url;
          });
      }      
      });

chrome.tabs.get(parseInt(tabid),function (tab,sendResponse) {
    if (request.action == "urlData"){
              if (tab != undefined) {
            sendResponse({tabid:tabid})
              }
            return true;
          };
});

//popup.js
let downloadButton = document.getElementById('getData');
downloadButton.onclick = function(element) {
  chrome.tabs.query({active: true,currentwindow: true},function (tabs) {
        
  chrome.tabs.onBeforeRequest(tabs[0].id,{
      action: "urlData",},function (response1){
      console.log(response1);
      $('#tabid').html(response.tabid);
  }
  });
};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)