I am working on a project which produces a Chrome extension. In my extension, I am using webRequest API to see inside a page websites. Then, I collect them and adding an array. I realized that, this array becomes empty after a time. In addition, it sometimes found 1 website sometimes 20 even 0. I mean it is not stable. What is the problem? How can I fix that? Here is my code:
function webRequestsChecking() {
let includedUrls = []
return new Promise((resolve, reject) => {
try {
chrome.webRequest.onBeforeRequest.addListener(
(details) => {
if (details !== undefined && details.parentFrameId !== -1) {
if (!includedUrls.includes(details.url.split('/')[2]))
includedUrls.push(details.url.split('/')[2])
}
console.log(includedUrls, 'setlemeden önce bg')
setIncludedUrls(includedUrls)
},
{ urls: ['<all_urls>'] },
[]
)
} catch (e) {
reject(e)
}
})
}
Also, I am adding a picture for more understandable: