0

With webRequest in was quite easy to do:

chrome.webRequest.onBeforeSendHeaders.addListener(this.addTabIdToHeader({ tabId }), { urls: ['http://*/*'] }, ['blocking', 'requestHeaders']);

Now in declarativeNetRequest there is no current tab id

            rule = {
                id: id,
                priority: 1,
                action: {
                    type: 'modifyHeaders',
                    requestHeaders: [{
                        header: 'X-SomeInfo-TabId',
                        operation: 'set',
                        value: \* ?? TabId ?? *\,
                    }],
                },
                condition: {
                    regexFilter: `http://${url}/.*`,
                    resourceTypes: ['main_frame'],
                },
            };
Paul Kamp
  • 101
  • 5
  • Use [updateSessionRules](https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#method-updateSessionRules) inside chrome.webRequest.onBeforeRequest – wOxxOm Jul 29 '22 at 11:29
  • hmm, In fact the problem is that blocking part of webRequest will be forbidded in 2023. I've got local proxy server and browser extension, if user wants to use my proxy I need to redirect it to my proxy. If there would be any custom errors I want to show user explanation just in that tab that he used. So I need somehow to provide to my proxy current tabId. – Paul Kamp Aug 01 '22 at 08:37
  • Then use it inside chrome.tabs.onCreated and add a rule for every tab id. – wOxxOm Aug 01 '22 at 08:44

0 Answers0