Do more on the web, with a fast and secure browser!

Download Opera browser with:

  • built-in ad blocker
  • battery saver
  • free VPN
Download Opera

add-on bug, need help

  • Hi, my Opera extension block access to url's, problem is my extension Block urls but i still can go to the index homes pages, so here it's a part of my code, need help to understand what's wrong and how i can correct that.
    also profanity words are not blocked Safe Search is off, but why !!!

    Here the code of my search.js

    "use strict";
    
    
    
    chrome.webRequest.onBeforeRequest.addListener(
    
    redirect,
    
    {urls: ["<all_urls>"], types: ["main_frame", "sub_frame"]},
    
    ["blocking"]
    
    );
    
    
    
    chrome.webNavigation.onReferenceFragmentUpdated.addListener(function(details) {
    
    if ( /webhp.*q=/.test(details.url) ) {
    
    let new_url = _add_if_necessary(details.url, "safe=active&ssui=on");
    
    if ( new_url ) {
    
    chrome.tabs.update(details.tabId, {'url': new_url});
    
    }
    
    }
    
    });
    
    
    
    function redirect(requestDetails) {
    
    let redir_url = _alter(requestDetails.url);
    
    if ( redir_url ) {
    
    return { redirectUrl: redir_url };
    
    }
    
    }
    
    
    
    
    
    function _alter(uri) {
    
    if ( uri.indexOf("google.") != -1 ) {
    
    if (/q=/.test(uri)) {
    
    return _add_if_necessary(uri, "safe=active&ssui=on");
    
    }
    
    } else if ( uri.indexOf("search.yahoo.") != -1 ) {
    
    if (/(\/search)/.test(uri)) {
    
    return _add_if_necessary(uri, "vm=r");
    
    }
    
    } else if ( uri.indexOf("bing.") != -1 ) {
    
    if (/(\/search|\/videos|\/images|\/news)/.test(uri)) {
    
    return _add_if_necessary(uri, "adlt=strict");
    
    }
    
    } else if ( uri.indexOf("duckduckgo.") != -1 ) {
    
    if ( uri.indexOf("q=") != -1 ) {
    
    return _add_if_necessary(uri, "kp=1");
    
    }
    
    } else if ( uri.indexOf("yandex.") != -1 ) {
    
    if ( uri.indexOf("/search") != -1 ) {
    
    return _add_if_necessary(uri, "fyandex=1");
    
    }
    
    }
    
    return false;
    
    }
    
    
    
    function _add_if_necessary(uri, needed_part) {
    
    if (uri.indexOf(needed_part) == -1) {
    
    return uri + "&" + needed_part;
    
    } else {
    
    return false;
    
    }
    
    }
    
    
    
    chrome.webRequest.onBeforeSendHeaders.addListener(
    
    function(details) {
    
    for (let i = 0; i < details.requestHeaders.length; ++i) {
    
    if (details.requestHeaders[i].name === 'YouTube-Restrict') {
    
    details.requestHeaders.splice(i, 1);
    
    break;
    
    }
    
    }
    
    details.requestHeaders.push({"name": "YouTube-Restrict",
    
    "value": "Moderate"});
    
    return {requestHeaders: details.requestHeaders};
    
    },
    
    {urls: ["*://*.youtube.com/*"], types: ["main_frame", "sub_frame"]},
    
    ["blocking", "requestHeaders"]
    
    );
    

    here my background.js file

    'use strict';
    
    let db = []; // session Global
    
    // ----- parse & cache the database data
    fetch('http://website/upload/db.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"]
    );
  • In fact my add-on works BUT i found something interesting !

    How in my add-on code i can activate all those functions by default ?
    0_1547637749282_opera_addon_modes.jpg

  • As far as I know, you can't.

  • @leocg well it has to be a way to solve this, i just want my add-on block the urls !!! problem is something doesn't work in my code and i have access to the index pages of blocked sites url's !

Log in to reply