Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the All The WebRequest Made by a selected Tab in Chrome A Extension

I want to get all the web request made by a tab and display it on the popup.html.

But the issue i am facing is.for eg. I opened a website in first tab and now I shift to second tab and open another site and shift back to first tab. So now when I shift back to first tab how can I get all the web request which was done by that website in the first tab previously before shifting the tab. So it will have to load again when I shift to the first tab.

I used below code to fetch the selected tab request

chrome.tabs.getSelected(null, function(tab){ 

    chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {

      console.log(details);

    }, {
    urls: ["<all_urls>"]
});
like image 933
Sam Avatar asked Nov 27 '25 20:11

Sam


1 Answers

  1. tabs.getSelected is deprecated since Chrome 33, use tabs.query:

    var myTabId;
    chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
        myTabId = tabs[0].id;
    });
    
  2. Check tabId in the callback of onBeforeSendHeaders:

    chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
        if (details.tabId == myTabId) {
            console.log(details);
        }
    });
    
like image 79
wOxxOm Avatar answered Nov 29 '25 08:11

wOxxOm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!