Home > Software engineering >  Intercept requests going from the sidebar panel
Intercept requests going from the sidebar panel

Time:02-23

Firefox allows us to apply filters like tabId, urls to requests before intercepting them using webRequest.RequestFilter

So far so good. The problem is this code

browser.sidebarAction.setPanel({
    panel: 'https://google.com'
});

Here we are requesting a web page that will be loaded into the sidebar (I want to intercept that request only)

As you can see it seems that there's no way to only filter sidebars' requests since even tabId will return the same id as the "parent" tab

Is it really possible to intercept requests going from the sidebar panel only?

CodePudding user response:

We can filter requests that aren't related to a tab by setting tabId to -1

browser.webRequest.onBeforeSendHeaders.addListener(
  listener,
  {
      urls: ["<all_urls>"],
      tabId: -1
  },
  ["blocking", "requestHeaders"]
);

This now matches our sidebar's requests

  • Related