Skip to content

Instantly share code, notes, and snippets.

@kzar
Last active October 22, 2025 16:43
Show Gist options
  • Select an option

  • Save kzar/01ea05e4758f5edbeebf9d09766ce456 to your computer and use it in GitHub Desktop.

Select an option

Save kzar/01ea05e4758f5edbeebf9d09766ce456 to your computer and use it in GitHub Desktop.
Log chrome webRequest and webNavigation events for blob URLs
function logEvent(type, details)
{
if (details.url.startsWith("blob"))
console.log(type, details);
}
/* WebNavigation */
chrome.webNavigation.onBeforeNavigate.addListener(details =>
{
logEvent("onBeforeNavigate", details);
});
chrome.webNavigation.onCommitted.addListener(details =>
{
logEvent("onCommitted", details);
});
chrome.webNavigation.onDOMContentLoaded.addListener(details =>
{
logEvent("onDOMContentLoaded", details);
});
chrome.webNavigation.onCompleted.addListener(details =>
{
logEvent("onCompleted", details);
});
/* WebRequest */
chrome.webRequest.onBeforeRequest.addListener(details =>
{
logEvent("onBeforeRequest", details);
}, {urls: ["<all_urls>"]}, ["blocking", "requestBody"]);
chrome.webRequest.onBeforeSendHeaders.addListener(details =>
{
logEvent("onBeforeSendHeaders", details);
}, {urls: ["<all_urls>"]}, ["blocking", "requestHeaders"]);
chrome.webRequest.onSendHeaders.addListener(details =>
{
logEvent("onSendHeaders", details);
}, {urls: ["<all_urls>"]}, ["requestHeaders"]);
chrome.webRequest.onHeadersReceived.addListener(details =>
{
logEvent("onHeadersReceived", details);
}, {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
chrome.webRequest.onResponseStarted.addListener(details =>
{
logEvent("onResponseStarted", details);
}, {urls: ["<all_urls>"]}, ["responseHeaders"]);
chrome.webRequest.onBeforeRedirect.addListener(details =>
{
logEvent("onBeforeRedirect", details);
}, {urls: ["<all_urls>"]}, ["responseHeaders"]);
chrome.webRequest.onCompleted.addListener(details =>
{
logEvent("onCompleted", details);
}, {urls: ["<all_urls>"]}, ["responseHeaders"]);
@Vessel9817
Copy link

Vessel9817 commented Oct 22, 2025

TL;DR - Sorry, doesn't work. Theoretically possible, but only with the scripting API, as far as I can tell.

As per Chromium issue 41406885, blob: URIs cannot be intercepted by webRequest. Having been trying to do the same thing in my own extension, webRequest, declarativeNetRequest, even debugger doesn't seem to be able to intercept them. Thus, I don't believe it's possible without injecting a script into every tab and overriding every method of producing a blob, which I will also be attempting. It's worth noting that I haven't tried using webNavigation, but I highly doubt it would have much success, either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment