Add-on BUG URGENT!


(Leonardo Sedevcic) #1

hi, i have a huge problem with my add-on i use:
‘use strict’;

let db = []; // session Global

// ----- parse & cache the database data
fetch(‘https://www.stop-it.be/upload/myfile.dat’)
.then(response => response.text())
.then(text => { db = text.trim().split(/[\r\n]+/); })
.catch(error => console.log(error));

chrome.webRequest.onBeforeRequest.addListener( details => {

let url = new URL(details.url);
return { cancel: url && url.hostname && db.includes(url.hostname) };

},
{urls: [“http:///”, “https:///”]},
[“blocking”]
);

BUT urls just ‘xxx.com’ url’s, inside the “myfile.dat” are no more blocked by my add-on do someone know why something is wrong??

myfile.dat is not the real name of my file, it’s just for explaining the error i have.
it’s URGENT !!!
Thanks


(Martin Giger) #2

Could you please try to format your post properly with code blocks if it is this urgent? It really helps with being able to read the code.

Further, myfile.dat has the format of one hostname per line?


(Leonardo Sedevcic) #3
'use strict';

let db = []; // session Global

// ----- parse & cache the database data
fetch('https://www.stop-it.be/upload/myfile.dat')
.then(response => response.text())
.then(text => { db = text.trim().split(/[\r\n]+/); })
.catch(error => console.log(error));

chrome.webRequest.onBeforeRequest.addListener( details => {

let url = new URL(details.url);
return { cancel: url && url.hostname && db.includes(url.hostname) };
}, 
{urls: ["http://*/*", "https://*/*"]},
["blocking"]
);

so here its my code inside the background.js

inside myfile.dat i just have urls in plain/text format like

badurl01.com
www.badurl1.com
badurl02.com
www.badurl2.com

etc…


(Martin Giger) #4

How far have you gone with investigating this? For example, is db already fully loaded when you are loading your URL and expecting it to be canceled? Have you looked at what the hostname is in the onBeforeRequest listener?


(Leonardo Sedevcic) #6

if i type for example on firefox or chrome the name of a xxx site without the .com, .xxx etc nothing appears,

BUT if i type the full name of a xxx site for example www.xxxxx.com or xxxxx.com it’s not blocked and i access to it :s

domains names are not blocked aymore :s
if i add the myfile.dat file inside the xpi file it works, but i dont want the huge database of bad urls be included inside the add-on, not safe for users

i’m shaking like and old tree :s hope to solve that :s


(Leonardo Sedevcic) #7

so i changed the manifest and did this:

"background": {
"scripts": ["background.js","search.js"],
"persistent": true
},
"browser_action":{ 
"browser_style": true, 
"default_icon":"Icon-48.png",
"default_popup":"popup.html"
},
"icons":{  
"48":"Icon-48.png"
},
"manifest_version":2,
"name":"Stop-it",
"permissions":[  
"http://*/*",
"https://*/*",
"webRequest",
"webNavigation",
"cookies",
"*://*.google.com/",
"*://*.duckduckgo.com/",
"*://*.yahoo.com/",
"*://*.yandex.com/",
"*://*.bing.com/",
"webRequestBlocking",
"<all_urls>"
],
"author":"Leonardo Sedevcic",
"version":"1.9.79",
"description":"The BEST Anti Porn, parental filter, betting & casinos, 
PornCams tool on the web, and many more",
"applications":{  
"gecko":{  
"id":"Stop-it.be@hotmail.com",
"strict_min_version":"52.0"
}
}
}

My add-on works under Chrome urls are blocked from
fetch(‘https://www.stop-it.be/upload/dburl.dat’)

but under firefox it doesnt work !!!

my background file looks like:

'use strict';

let db = []; // session Global

// ----- parse & cache the database data
fetch('https://www.stop-it.be/upload/dburl.dat')
.then(response => response.text())
.then(text => { db = text.trim().split(/[\r\n]+/); })
.catch(error => console.log(error));

chrome.webRequest.onBeforeRequest.addListener( details => {

let url = new URL(details.url);
return { cancel: url && url.hostname && db.includes(url.hostname) };
}, 
{urls: ["http://*/*", "https://*/*"]},
["blocking"]
);

(jscher2000) #8

There’s a different thread that starts with “Hi i solved my proble for my add-on but i get in a new problem!”

Does that mean you can close this thread? Do you want to mention any lesson learned for others who have the same isue?


(Leonardo Sedevcic) #9

Solved, i hosted the database in another domain name, now my add-on block request from the db and also prevent users to access to the db.

Thanks to everyone !