Manifest v3: Redirect to internal extension page

794 views
Skip to first unread message

dspi

unread,
Jan 21, 2022, 7:27:16 AM1/21/22
to Chromium Extensions
Hello, i'm kinda new to the manifest v3 transition and i wanted to know if there is a way to redirect a website using static rules to a custom html page within the extension. In manifest v2 this was done by getting the url and redirecting from js but i don't see how it's possible to do so now using the static rules.

If there is a way to do this or any other recommended course of action please let me know

wOxxOm

unread,
Jan 21, 2022, 9:08:53 AM1/21/22
to Chromium Extensions, dspi
It depends on how flexible the logic should be. For simple cases you can use declarativeNetRequest, otherwise you should show the relevant code so we can try to find a solution or confirm there is none in MV3.

dspi

unread,
Jan 21, 2022, 11:37:35 AM1/21/22
to Chromium Extensions, wOxxOm, dspi
I have a manifest v2 extension that simply detected whether a website was in a list and redirected it to a "blocked" page inside the extension, a.k.a a simple html file. The url for this file was generated by the function `chrome.extension.getURL("src/blocked.html")`. Since webrequestBlocking is going to disappear, how do i translate this behaviour to DNR? Rulesets don't allow this particular behaviour afaik.

wOxxOm

unread,
Jan 21, 2022, 12:17:07 PM1/21/22
to Chromium Extensions, dspi, wOxxOm
Since you don't add a variable portion to the redirected URL, declarativeNetRequest is perfectly fine.

If the web sites are known you can declare the rules in a static json as shown in the documentation examples.

If the web sites are configurable by the user you can add dynamic rules using chrome.declarativeNetRequest.updateDynamicRules and specify `extensionPath` in the redirect action.

馮韋元

unread,
Jan 21, 2022, 8:40:27 PM1/21/22
to Chromium Extensions, wOxxOm, dspi
Yes, you could use a rule similar to that:

var redirectFile = chrome.runtime.getURL("./ui/localpage.html");

{
                action: {
                    type: "redirect",
                    redirect: {
                        regexSubstitution: redirectFile + "?url=\\0"
                    }
                },
                condition: {"regexFilter": "^https://www\.mywebsite\.com$", "resourceTypes": ["main_frame"]},
                id: ruleIdx
                priority: 1
            }    

It will even keep the original parameters thanks to \\0 so that your local page perform operations based on the original URL.

Regards,
Francois

Death Time

unread,
Apr 5, 2022, 6:55:13 AM4/5/22
to Chromium Extensions, 馮韋元, wOxxOm, dspi
What about if it is a big Commercially used security providing extension and we have a really big Urls and regex feed to keep users safe from all types of malicious attacks.
How can we add all these URLs in rules which are going to be dynamic as the feed is going to be updated every day?  When the current limit is only 5k.

Reply all
Reply to author
Forward
0 new messages