I have a manifest v3 chrome browser extension where I need to intercept a website doing a HTTP request to a custom protocol.
When I open Network Developer Tools on that website I can see that the website tries to do a request to internal://callback
. The request is obviously (canceled)
but I need a way to detect this in my extension and get a URL of that request.
I tried webRequest API
but it's only capable of intercepting "standart" protocols.
only the following schemes are accessible: http://, https://, ftp://, file://, ws:// (since Chrome 58), wss:// (since Chrome 58), urn: (since Chrome 91), or chrome-extension://.
chrome.webRequest.onBeforeRequest.addListener(
(details) => {
console.debug("onBeforeRequest", details);
if (details.url.includes("internal")) {
// never executes
}
},
{ urls: ["<all_urls>"] },
["extraHeaders", "requestBody"]
);
In the end I found that the custom protocol I need is present as a redirect url in one of the redirect requests, so I was able to use that:
chrome.webRequest.onBeforeRedirect.addListener(
(details) => {
const { redirectUrl } = details;
if (redirectUrl.startsWith("internal://")) {
// ...do the thing
}
},
{ urls: ["<all_urls>"] }
);