Hi everyone,
I am relatively newer to browser extension development, and I am concerned I am using the wrong event handler or seeing a new bug. I am currently hooking chrome.webRequest.onCompleted for Firefox & Chrome tab requests for analytics purposes.
Normally refresh and new page visits trigger many events for all incoming data, but what I have found on Chrome and Firefox is that usually page visits and refreshes produce main_frame
type. What I have been seeing only in Firefox is that refreshes occasionally do not refresh the main_frame though some resources seem to recycle. I believe this to have started with Firefox 122, but I do not have the spare system to try before it.
chrome.webRequest.onCompleted.addListener(function (details: chrome.webRequest.WebResponseCacheDetails) {
if (
(details.initiator && details.initiator.startsWith("chrome-extension://")) ||
(details.url && details.url.startsWith("chrome-extension://")) ||
details.tabId < 0
){
return;
}
if (details.type == "main_frame") {
clearData(details.tabId);
// Main Tab Request
const instance = new Instance(details); // Data processing and stuff...
const timer = setInterval(function() {
instance.LogToConsole();
clearInterval(timer);
}, 2000);
} else if (
details.type === "sub_frame" ||
details.type === "stylesheet" ||
details.type === "script" ||
details.type === "image" ||
details.type === "xmlhttprequest"
){
// Tab Sub-Requests
// Data processing and stuff...
}
}