Replacing webRequest with declarativeNetRequest API manifest v3

909 views
Skip to first unread message

Sangeetha Panneerselvam

unread,
Aug 24, 2021, 1:12:13 PM8/24/21
to Chromium Extensions
The below is the highlevel code structure for chrome extension development I am working on. For some functions, I have mentioned the function name alone, instead full code, as it huge code with more than 1500 lines of code.

But this where webRequest API involves, where I need to replace declarativeNetRequest API. I don't see anywhere declarativeNetRequest will be useful for involving this complex code with so many function blocks nested in.

Anyone please provide the suggestion on manifest migration to v3 in case of webRequest and webRequest blocking. 

Note: ExtensionInstallForcelist cannot be used for my extension.

function fnBlockC() {
  chrome.webRequest.onCompleted.addListener(
    function (details) {
       // some code here
          fnBlockE()
          fnBlockF()
})
}

fnBlockD()
fnBlockG()
fnBlockH()

fnBlockA()
fnCallback

fnBlockB()
fnCallback

fnCallback
fnBlockE()
fnBlockF()

function   fnBlockA() {
  chrome.webRequest.onBeforeRequest.addListener(
      fnCallback,
    {
      urls: ["<all_urls>"],
    },
    ["blocking"]
  );
}

function  fnBlockB() {
  chrome.webRequest.onBeforeRequest.removeListener(
      fnCallback,
    {
      urls: ["<all_urls>"],
    },
    ["blocking"]
  );
}

Deco

unread,
Aug 24, 2021, 1:24:29 PM8/24/21
to Sangeetha Panneerselvam, Chromium Extensions
This is a very inefficient and redundant method of building web request functions. 90% of this code could have been shortened down programmatically, but now there is no way for you to conveniently migrate the code over due to it being built, I hate to say badly to begin with. 

Your own really option is to build the code from scratch - I advise you to read the documentation for declarativeNetRequest seriously and this time build it in an optimised fashion.

Thanks,
Deco


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/271c4dce-0e0e-4c1c-9363-42a760dd92d7n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages