• Login
    • Search
    • Categories
    • Recent
    • Tags
    • Users
    • Groups
    • Rules
    • Help

    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

    Opera add-ons
    2
    4
    1380
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • stop--it
      stop--it last edited by stop--it

      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"]
      );
      
      Reply Quote 0
        1 Reply Last reply
      • stop--it
        stop--it last edited by

        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

        Reply Quote 0
          leocg 1 Reply Last reply
        • leocg
          leocg Moderator Volunteer @stop--it last edited by

          As far as I know, you can't.

          Reply Quote 0
            stop--it 1 Reply Last reply
          • stop--it
            stop--it @leocg last edited by

            @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 !

            Reply Quote 1
              1 Reply Last reply
            • First post
              Last post

            Computer browsers

            • Opera for Windows
            • Opera for Mac
            • Opera for Linux
            • Opera beta version
            • Opera USB

            Mobile browsers

            • Opera for Android
            • Opera Mini
            • Opera Touch
            • Opera for basic phones

            • Add-ons
            • Opera account
            • Wallpapers
            • Opera Ads

            • Help & support
            • Opera blogs
            • Opera forums
            • Dev.Opera

            • Security
            • Privacy
            • Cookies Policy
            • EULA
            • Terms of Service

            • About Opera
            • Press info
            • Jobs
            • Investors
            • Become a partner
            • Contact us

            Follow Opera

            • Opera - Facebook
            • Opera - Twitter
            • Opera - YouTube
            • Opera - LinkedIn
            • Opera - Instagram

            © Opera Software 1995-2025