Chrome extension don't block urls need A SOLUTION.

77 views
Skip to first unread message

Leonardo Sedevcic

unread,
Apr 18, 2015, 7:38:28 PM4/18/15
to chromium-...@chromium.org
Hello to everyone, i hope to get some help here.

My chrome extension blocks bad urls and work very well more than 23.000 users actually.

Bu in my extension i would like to block that kind of url: twitter.com/PornoBrazil


The code of my app "background.js":

var AUTHORIZED_DOMAINS= {
"siteporno.com": false,
"www.siteporno.com": false
};
function extract_domain(url)    {
    var matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
    return matches[1];
}
 
chrome.webRequest.onBeforeRequest.addListener(function(details) { 
var domain = extract_domain(details.url);
return { cancel: AUTHORIZED_DOMAINS[domain ]===false }; 
}, {urls: ["<all_urls>"]},["blocking"]);

My extension don't block the twitter bad urls.
Can someone help me to end with this problem?

thanks :D

Jim Adamson

unread,
Apr 19, 2015, 5:58:20 AM4/19/15
to chromium-...@chromium.org
Hello,

At a quick glance it looks like the regular expression in the function extract_domain only extracts the domain (i.e. twitter.com), not the path (i.e. /PornoBrazil). I'd suggest modifying the regular expression so that it returns matches against the domain and path.

Jim

Leonardo Sedevcic

unread,
Apr 19, 2015, 6:22:15 AM4/19/15
to chromium-...@chromium.org
How i can do that, what i have to change?  
thanks

Jehudi Castro Sierra

unread,
Apr 19, 2015, 7:53:57 AM4/19/15
to Leonardo Sedevcic, chromium-...@chromium.org

On Sun, Apr 19, 2015 at 12:22 PM, Leonardo Sedevcic <mattepai...@gmail.com> wrote:
How i can do that, what i have to change?  
thanks

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/b697f390-4c6d-49a1-a4a7-382025d8632d%40chromium.org.

Leonardo Sedevcic

unread,
Apr 19, 2015, 8:27:27 AM4/19/15
to chromium-...@chromium.org
well this is not helping me :s i would like to know what detail i have to change in my code.
i have many thousands urls blocked by my extension. so i have to know how to quick correct my code and not starting from zero.

Daniel F

unread,
Apr 19, 2015, 11:37:36 AM4/19/15
to chromium-...@chromium.org
You will be much better off if you learn your self. I highly recomend http://regexr.com/ , it will let you see the results of a regex expression as you type.

If I were you, I would sit down and think through exactly how the regex should work. Do you want to only look at the last bit of the path, or the entire path? It may even be easier to just look for bad words in the entire domain.

Then, research how to do each step of the process.

Leonardo Sedevcic

unread,
Apr 19, 2015, 1:29:29 PM4/19/15
to chromium-...@chromium.org
the entire path

actually my app block urls like this:


but if i have a website like twitter it don't want to block the url.

if i have
twitter.com the url is blocked
but if i have twitter.com/amberwestmodel the url is not blocked. it is because of the / or because twitter is an https?


Daniel F

unread,
Apr 20, 2015, 6:54:24 AM4/20/15
to chromium-...@chromium.org
You will continuously run into errors if you don't understand what your code does. Take the time to actually learn what it is doing.

Try console.log every time you change a variable, and see what you learn.
Reply all
Reply to author
Forward
0 new messages