Skip to content

Instantly share code, notes, and snippets.

@kzar
Last active February 20, 2024 02:53
Show Gist options
  • Save kzar/01ea05e4758f5edbeebf9d09766ce456 to your computer and use it in GitHub Desktop.
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"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment