Chrome extension Redirection???

25 views
Skip to first unread message

Leonardo Sedevcic

unread,
Feb 1, 2018, 6:36:22 AM2/1/18
to apps-dev
Hi have a chrome extension who block urls and cancel request, so i get a cancel page with a short message, telling me the page was blocked by an add-on.

What i would like to achieve is instead of doing a cancel is i NEED absolutely to do a simple redirection to 'google.com'.

This is my code:

'use strict';

let db = []; // session Global

// ----- parse & cache the database data
fetch('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"]
);


Thanks to everyone who can help me with my problem !

I need to change something inside this to make a redirection to google.com if the user try to reach one url fetch from the 'db.dat'.
Reply all
Reply to author
Forward
0 new messages