I would like to create a script (which may become a Chrome extension in the future) that reads the request log and searches for keywords in urls. The goal is to build a script that replaces the manual check of the:
- open Network
- filter for a keywork
- see what clicks in the request urls.
If it finds something then it creates a popup to alert me otherwise it returns an error.
I have tried several scripts but it seems that the problem is in reading the network log.
This is the last script I used, how can I improve it?
// Funzione per monitorare le richieste di rete
function monitorNetworkRequests() {
// Intercetta le richieste di rete usando l'API PerformanceObserver
const observer = new PerformanceObserver((list) => {
const entries = list.getEntries();
entries.forEach((entry) => {
const url = entry.name.toLowerCase();
// Controlla se l'URL contiene "adform" o "doubleclick"
if (url.includes("adform")) {
showPopup("Tracciamenti di adform implementati!");
} else if (url.includes("doubleclick")) {
showPopup("Tracciamenti di doubleclick implementati!");
} else {
showPopup("Tracciamenti non implementati!");
}
});
});
observer.observe({ type: "resource", buffered: true });
}
// Funzione per mostrare un popup al centro dello schermo
function showPopup(message) {
const popup = document.createElement("div");
popup.innerText = message;
popup.style.position = "fixed";
popup.style.top = "50%";
popup.style.left = "50%";
popup.style.transform = "translate(-50%, -50%)";
popup.style.backgroundColor = "rgba(0, 0, 0, 0.8)";
popup.style.color = "white";
popup.style.padding = "20px";
popup.style.borderRadius = "8px";
popup.style.fontSize = "16px";
popup.style.zIndex = "10000";
document.body.appendChild(popup);
// Rimuove il popup dopo 3 secondi
setTimeout(() => {
popup.remove();
}, 3000);
}
// Avvia il monitoraggio delle richieste di rete
monitorNetworkRequests();