chrome.declarativeNetRequest Callback ?

150 views
Skip to first unread message

MV3 Noob

unread,
Feb 6, 2023, 5:29:41 AM2/6/23
to Chromium Extensions
I have 2 related questions on MV3 chrome.declarativeNetRequest:

1. On MV2, when i was blocking a domain i could run a chrome.tabs.remove(tab.id) to remove the page as well.
On MV3 i don't know where to trigger a callback to the chrome.declarativeNetRequest

2. How do i specify to show a local html page when a rule blocks a domain ? Should i specify "redirect" instead of "block" ? or is there a method where i can keep the rule as "block" and then show a local page ?

Thanks !


wOxxOm

unread,
Feb 6, 2023, 11:08:09 AM2/6/23
to Chromium Extensions, MV3 Noob
You can redirect to a local html page in your extension:
  • "redirect": {"extensionPath": "/close.html"} in the rule
  • "web_accessible_resources": [{"resources": ["/close.html"], "matches": ["<all_urls>"]}] in manifest.json
  • window.close() or chrome.tabs.getCurrent(t => chrome.tabs.remove(t.id))  in the script of this close.html page
If you want to see the URL of the blocked page in your close.html script you would need regexFilter and regexSubstitution as shown in https://stackoverflow.com/a/73392754

MV3 Noob

unread,
Feb 10, 2023, 4:15:43 AM2/10/23
to Chromium Extensions, wOxxOm, MV3 Noob
Thanks a lot, it the solution i was thinking but i couldn't believe that there is no callback on such an important feature. Is there any other way ?

wOxxOm

unread,
Feb 10, 2023, 5:34:47 AM2/10/23
to Chromium Extensions, MV3 Noob, wOxxOm
No. This API is not designed to make your life easier.
Reply all
Reply to author
Forward
0 new messages