monitor the browser url in browser extension

I want to create a browser extension to help me search for words each time I open a web page.
I want to add a listener to the browser that will alert the extension each time the user enter a new website so it could scan the new page.
How can I add a listener (or perhaps there is another way to do it?)

Also I write my extension in angular 5 ,so if I can add a listener for angular it will be great

chrome is undefined in microsoft edge extension

Good day, I’ve written an extension which I would like run on every platform/browser. It works fine with chrome and firefox but just got error with ie-edge on windows 10. It keeps throwing chrome is not defined. Is there a way to make it define as I’ve been using through out my extension.

Thanks

export default {
  browserAction: {
    onClicked: chrome.browserAction !== undefined ? chrome.browserAction.onClicked : undefined,
    setBadgeText: chrome.browserAction !== undefined ? chrome.browserAction.setBadgeText : undefined,
    setTitle: chrome.browserAction !== undefined ? chrome.browserAction.setTitle : undefined,
    setIcon: chrome.browserAction !== undefined ? chrome.browserAction.setIcon : undefined,
  },
  extension: {
    getURL: chrome.extension !== undefined ? chrome.extension.getURL : undefined,
  },
  runtime: {
    onMessage: chrome.runtime.onMessage || browser.runtime.onMessage,
    reload: chrome.runtime.reload,
    sendMessage: chrome.runtime.sendMessage,
  },
  tabs: {
    create: chrome.tabs !== undefined ? chrome.tabs.create : undefined,
    executeScript: chrome.tabs !== undefined ? chrome.tabs.executeScript : undefined,
    get: chrome.tabs !== undefined ? chrome.tabs.get : undefined,
    onActivated: chrome.tabs !== undefined ? chrome.tabs.onActivated : undefined,
    onUpdated: chrome.tabs !== undefined ? chrome.tabs.onUpdated : undefined,
    query: chrome.tabs !== undefined ? chrome.tabs.query : undefined,
    remove: chrome.tabs !== undefined ? chrome.tabs.remove : undefined,
    sendMessage: chrome.tabs !== undefined ? chrome.tabs.sendMessage : undefined,
  },
  webRequest: {
    onBeforeRedirect: chrome.tabs !== undefined ? chrome.webRequest.onBeforeRedirect : undefined,
  },
};

EXT to stript Google urls – to give direct links – what’s wrong?

I’m having trouble getting cleanurls.js working. Other parts of the ext are working. Cleanurls.js should clean Google Search result urls so that direct link is given when for example link url copied. What am I missing?

The purpose of the ext is to direct Google Search queries from omnibox to encrypted.google.com – this part of the ext is working.

Second part of the ext is to clean Google search result urls from trash: trackers and such – and give a clean url. But I’m not getting cleanurls.js working. Resolute shouldn’t be far… But something is wrong in it.

Could you be so kind and check it and guide me to right direction?

{
	"name": "name here",
	"version": "1.0",
	"manifest_version": 2,
	"description": "desch here",
	"developer": {
		"name": "dev here"
	},
	"icons": {
	"16": "16.png",
	"19": "19.png",
	"38": "38.png",
	"48": "48.png",
	"128": "128.png"
  },
	"permissions": [
		"webRequest",
		"webRequestBlocking",
		"storage",
		"tabs",
		"*://*.google.ad/*",
		"*://*.google.ae/*",
		"*://*.google.com.af/*",
		"*://*.google.com.ag/*",
		"*://*.google.com.ai/*",
		"*://*.google.al/*",
		"*://*.google.am/*",
		"*://*.google.co.ao/*",
		"*://*.google.com.ar/*",
		"*://*.google.as/*",
		"*://*.google.at/*",
		"*://*.google.com.au/*",
		"*://*.google.az/*",
		"*://*.google.ba/*",
		"*://*.google.com.bd/*",
		"*://*.google.be/*",
		"*://*.google.bf/*",
		"*://*.google.bg/*",
		"*://*.google.com.bh/*",
		"*://*.google.bi/*",
		"*://*.google.bj/*",
		"*://*.google.com.bn/*",
		"*://*.google.com.bo/*",
		"*://*.google.com.br/*",
		"*://*.google.bs/*",
		"*://*.google.bt/*",
		"*://*.google.co.bw/*",
		"*://*.google.by/*",
		"*://*.google.com.bz/*",
		"*://*.google.ca/*",
		"*://*.google.cd/*",
		"*://*.google.cf/*",
		"*://*.google.cg/*",
		"*://*.google.ch/*",
		"*://*.google.ci/*",
		"*://*.google.co.ck/*",
		"*://*.google.cl/*",
		"*://*.google.cm/*",
		"*://*.google.cn/*",
		"*://*.google.com.co/*",
		"*://*.google.co.cr/*",
		"*://*.google.com.cu/*",
		"*://*.google.cv/*",
		"*://*.google.com.cy/*",
		"*://*.google.cz/*",
		"*://*.google.de/*",
		"*://*.google.dj/*",
		"*://*.google.dk/*",
		"*://*.google.dm/*",
		"*://*.google.com.do/*",
		"*://*.google.dz/*",
		"*://*.google.com.ec/*",
		"*://*.google.ee/*",
		"*://*.google.com.eg/*",
		"*://*.google.es/*",
		"*://*.google.com.et/*",
		"*://*.google.fi/*",
		"*://*.google.com.fj/*",
		"*://*.google.fm/*",
		"*://*.google.fr/*",
		"*://*.google.ga/*",
		"*://*.google.ge/*",
		"*://*.google.gg/*",
		"*://*.google.com.gh/*",
		"*://*.google.com.gi/*",
		"*://*.google.gl/*",
		"*://*.google.gm/*",
		"*://*.google.gp/*",
		"*://*.google.gr/*",
		"*://*.google.com.gt/*",
		"*://*.google.gy/*",
		"*://*.google.com.hk/*",
		"*://*.google.hn/*",
		"*://*.google.hr/*",
		"*://*.google.ht/*",
		"*://*.google.hu/*",
		"*://*.google.co.id/*",
		"*://*.google.ie/*",
		"*://*.google.co.il/*",
		"*://*.google.im/*",
		"*://*.google.co.in/*",
		"*://*.google.iq/*",
		"*://*.google.is/*",
		"*://*.google.it/*",
		"*://*.google.je/*",
		"*://*.google.com.jm/*",
		"*://*.google.jo/*",
		"*://*.google.co.jp/*",
		"*://*.google.co.ke/*",
		"*://*.google.com.kh/*",
		"*://*.google.ki/*",
		"*://*.google.kg/*",
		"*://*.google.co.kr/*",
		"*://*.google.com.kw/*",
		"*://*.google.kz/*",
		"*://*.google.la/*",
		"*://*.google.com.lb/*",
		"*://*.google.li/*",
		"*://*.google.lk/*",
		"*://*.google.co.ls/*",
		"*://*.google.lt/*",
		"*://*.google.lu/*",
		"*://*.google.lv/*",
		"*://*.google.com.ly/*",
		"*://*.google.co.ma/*",
		"*://*.google.md/*",
		"*://*.google.me/*",
		"*://*.google.mg/*",
		"*://*.google.mk/*",
		"*://*.google.ml/*",
		"*://*.google.com.mm/*",
		"*://*.google.mn/*",
		"*://*.google.ms/*",
		"*://*.google.com.mt/*",
		"*://*.google.mu/*",
		"*://*.google.mv/*",
		"*://*.google.mw/*",
		"*://*.google.com.mx/*",
		"*://*.google.com.my/*",
		"*://*.google.co.mz/*",
		"*://*.google.com.na/*",
		"*://*.google.com.nf/*",
		"*://*.google.com.ng/*",
		"*://*.google.com.ni/*",
		"*://*.google.ne/*",
		"*://*.google.nl/*",
		"*://*.google.no/*",
		"*://*.google.com.np/*",
		"*://*.google.nr/*",
		"*://*.google.nu/*",
		"*://*.google.co.nz/*",
		"*://*.google.com.om/*",
		"*://*.google.com.pa/*",
		"*://*.google.com.pe/*",
		"*://*.google.com.pg/*",
		"*://*.google.com.ph/*",
		"*://*.google.com.pk/*",
		"*://*.google.pl/*",
		"*://*.google.pn/*",
		"*://*.google.com.pr/*",
		"*://*.google.ps/*",
		"*://*.google.pt/*",
		"*://*.google.com.py/*",
		"*://*.google.com.qa/*",
		"*://*.google.ro/*",
		"*://*.google.ru/*",
		"*://*.google.rw/*",
		"*://*.google.com.sa/*",
		"*://*.google.com.sb/*",
		"*://*.google.sc/*",
		"*://*.google.se/*",
		"*://*.google.com.sg/*",
		"*://*.google.sh/*",
		"*://*.google.si/*",
		"*://*.google.sk/*",
		"*://*.google.com.sl/*",
		"*://*.google.sn/*",
		"*://*.google.so/*",
		"*://*.google.sm/*",
		"*://*.google.sr/*",
		"*://*.google.st/*",
		"*://*.google.com.sv/*",
		"*://*.google.td/*",
		"*://*.google.tg/*",
		"*://*.google.co.th/*",
		"*://*.google.com.tj/*",
		"*://*.google.tk/*",
		"*://*.google.tl/*",
		"*://*.google.tm/*",
		"*://*.google.tn/*",
		"*://*.google.to/*",
		"*://*.google.com.tr/*",
		"*://*.google.tt/*",
		"*://*.google.com.tw/*",
		"*://*.google.co.tz/*",
		"*://*.google.com.ua/*",
		"*://*.google.co.ug/*",
		"*://*.google.co.uk/*",
		"*://*.google.com.uy/*",
		"*://*.google.co.uz/*",
		"*://*.google.com.vc/*",
		"*://*.google.co.ve/*",
		"*://*.google.vg/*",
		"*://*.google.co.vi/*",
		"*://*.google.com.vn/*",
		"*://*.google.vu/*",
		"*://*.google.ws/*",
		"*://*.google.rs/*",
		"*://*.google.co.za/*",
		"*://*.google.co.zm/*",
		"*://*.google.co.zw/*",
		"*://*.google.cat/*"
	],
	"background": {
		"scripts": [
			"encryptedredirect.js"
		]
	},
	"page_action": {
		"default_icon": "38.png",
		"default_title": "title here"
	},
	"content_scripts": [
		{
			"matches": [
				"*://*.google.ad/*",
				"*://*.google.ae/*",
				"*://*.google.com.af/*",
				"*://*.google.com.ag/*",
				"*://*.google.com.ai/*",
				"*://*.google.al/*",
				"*://*.google.am/*",
				"*://*.google.co.ao/*",
				"*://*.google.com.ar/*",
				"*://*.google.as/*",
				"*://*.google.at/*",
				"*://*.google.com.au/*",
				"*://*.google.az/*",
				"*://*.google.ba/*",
				"*://*.google.com.bd/*",
				"*://*.google.be/*",
				"*://*.google.bf/*",
				"*://*.google.bg/*",
				"*://*.google.com.bh/*",
				"*://*.google.bi/*",
				"*://*.google.bj/*",
				"*://*.google.com.bn/*",
				"*://*.google.com.bo/*",
				"*://*.google.com.br/*",
				"*://*.google.bs/*",
				"*://*.google.bt/*",
				"*://*.google.co.bw/*",
				"*://*.google.by/*",
				"*://*.google.com.bz/*",
				"*://*.google.ca/*",
				"*://*.google.cd/*",
				"*://*.google.cf/*",
				"*://*.google.cg/*",
				"*://*.google.ch/*",
				"*://*.google.ci/*",
				"*://*.google.co.ck/*",
				"*://*.google.cl/*",
				"*://*.google.cm/*",
				"*://*.google.cn/*",
				"*://*.google.com.co/*",
				"*://*.google.co.cr/*",
				"*://*.google.com.cu/*",
				"*://*.google.cv/*",
				"*://*.google.com.cy/*",
				"*://*.google.cz/*",
				"*://*.google.de/*",
				"*://*.google.dj/*",
				"*://*.google.dk/*",
				"*://*.google.dm/*",
				"*://*.google.com.do/*",
				"*://*.google.dz/*",
				"*://*.google.com.ec/*",
				"*://*.google.ee/*",
				"*://*.google.com.eg/*",
				"*://*.google.es/*",
				"*://*.google.com.et/*",
				"*://*.google.fi/*",
				"*://*.google.com.fj/*",
				"*://*.google.fm/*",
				"*://*.google.fr/*",
				"*://*.google.ga/*",
				"*://*.google.ge/*",
				"*://*.google.gg/*",
				"*://*.google.com.gh/*",
				"*://*.google.com.gi/*",
				"*://*.google.gl/*",
				"*://*.google.gm/*",
				"*://*.google.gp/*",
				"*://*.google.gr/*",
				"*://*.google.com.gt/*",
				"*://*.google.gy/*",
				"*://*.google.com.hk/*",
				"*://*.google.hn/*",
				"*://*.google.hr/*",
				"*://*.google.ht/*",
				"*://*.google.hu/*",
				"*://*.google.co.id/*",
				"*://*.google.ie/*",
				"*://*.google.co.il/*",
				"*://*.google.im/*",
				"*://*.google.co.in/*",
				"*://*.google.iq/*",
				"*://*.google.is/*",
				"*://*.google.it/*",
				"*://*.google.je/*",
				"*://*.google.com.jm/*",
				"*://*.google.jo/*",
				"*://*.google.co.jp/*",
				"*://*.google.co.ke/*",
				"*://*.google.com.kh/*",
				"*://*.google.ki/*",
				"*://*.google.kg/*",
				"*://*.google.co.kr/*",
				"*://*.google.com.kw/*",
				"*://*.google.kz/*",
				"*://*.google.la/*",
				"*://*.google.com.lb/*",
				"*://*.google.li/*",
				"*://*.google.lk/*",
				"*://*.google.co.ls/*",
				"*://*.google.lt/*",
				"*://*.google.lu/*",
				"*://*.google.lv/*",
				"*://*.google.com.ly/*",
				"*://*.google.co.ma/*",
				"*://*.google.md/*",
				"*://*.google.me/*",
				"*://*.google.mg/*",
				"*://*.google.mk/*",
				"*://*.google.ml/*",
				"*://*.google.com.mm/*",
				"*://*.google.mn/*",
				"*://*.google.ms/*",
				"*://*.google.com.mt/*",
				"*://*.google.mu/*",
				"*://*.google.mv/*",
				"*://*.google.mw/*",
				"*://*.google.com.mx/*",
				"*://*.google.com.my/*",
				"*://*.google.co.mz/*",
				"*://*.google.com.na/*",
				"*://*.google.com.nf/*",
				"*://*.google.com.ng/*",
				"*://*.google.com.ni/*",
				"*://*.google.ne/*",
				"*://*.google.nl/*",
				"*://*.google.no/*",
				"*://*.google.com.np/*",
				"*://*.google.nr/*",
				"*://*.google.nu/*",
				"*://*.google.co.nz/*",
				"*://*.google.com.om/*",
				"*://*.google.com.pa/*",
				"*://*.google.com.pe/*",
				"*://*.google.com.pg/*",
				"*://*.google.com.ph/*",
				"*://*.google.com.pk/*",
				"*://*.google.pl/*",
				"*://*.google.pn/*",
				"*://*.google.com.pr/*",
				"*://*.google.ps/*",
				"*://*.google.pt/*",
				"*://*.google.com.py/*",
				"*://*.google.com.qa/*",
				"*://*.google.ro/*",
				"*://*.google.ru/*",
				"*://*.google.rw/*",
				"*://*.google.com.sa/*",
				"*://*.google.com.sb/*",
				"*://*.google.sc/*",
				"*://*.google.se/*",
				"*://*.google.com.sg/*",
				"*://*.google.sh/*",
				"*://*.google.si/*",
				"*://*.google.sk/*",
				"*://*.google.com.sl/*",
				"*://*.google.sn/*",
				"*://*.google.so/*",
				"*://*.google.sm/*",
				"*://*.google.sr/*",
				"*://*.google.st/*",
				"*://*.google.com.sv/*",
				"*://*.google.td/*",
				"*://*.google.tg/*",
				"*://*.google.co.th/*",
				"*://*.google.com.tj/*",
				"*://*.google.tk/*",
				"*://*.google.tl/*",
				"*://*.google.tm/*",
				"*://*.google.tn/*",
				"*://*.google.to/*",
				"*://*.google.com.tr/*",
				"*://*.google.tt/*",
				"*://*.google.com.tw/*",
				"*://*.google.co.tz/*",
				"*://*.google.com.ua/*",
				"*://*.google.co.ug/*",
				"*://*.google.co.uk/*",
				"*://*.google.com.uy/*",
				"*://*.google.co.uz/*",
				"*://*.google.com.vc/*",
				"*://*.google.co.ve/*",
				"*://*.google.vg/*",
				"*://*.google.co.vi/*",
				"*://*.google.com.vn/*",
				"*://*.google.vu/*",
				"*://*.google.ws/*",
				"*://*.google.rs/*",
				"*://*.google.co.za/*",
				"*://*.google.co.zm/*",
				"*://*.google.co.zw/*",
				"*://*.google.cat/*"
			],
			"run_at": "document_start",
			"js": [
				"cleanurls.js"
			]
		}
	]
}
// cleanurls.js 

window.addEventListener("mousedown", saveLinkTarget, true);
window.addEventListener("mousedown", restoreLinkTarget, false);
window.addEventListener("click", interceptEvent, true);
window.addEventListener("keydown", interceptEvent, true);

function detach()
{
  try
  {
    window.removeEventListener("mousedown", saveLinkTarget, true);
    window.removeEventListener("mousedown", restoreLinkTarget, false);
    window.removeEventListener("click", interceptEvent, true);
    window.removeEventListener("keydown", interceptEvent, true);
  }
  catch (e)
  {
    // Ignore for window unload
  }
}

let currentLink = null;
let currentLinkHref = null;

let hosts = {
  "groups.google.com": "google-groups"
};

let containerAttr = {
  "google": ["id", "search"],
  "google-groups": ["role", "main"],
  "google-news": ["class", "content-pane-container"],
};

function isSearchPage(window)
{
  try
  {
    let host = window.location.host;
    if (hosts.hasOwnProperty(host))
      return hosts[host];

    host = host.replace(/^.*?./, "");
    if (hosts.hasOwnProperty(host))
      return hosts[host];
  }
  catch (e)
  {
    // host throw special page
  }

  // Google detect search pages
  if (document instanceof HTMLDocument)
  {
    let eventName = "cleanurls" + Math.random();
    let script = document.createElement("script");
    script.async = false;
    script.textContent = "if (window.google && (window.google.sn || window.google.search))" +
                           "window.dispatchEvent(new Event('" + eventName + "'))";

    let isGoogle = false;
    let handler = () => isGoogle = true;
    window.addEventListener(eventName, handler, true);
    document.documentElement.appendChild(script);
    document.documentElement.removeChild(script);
    window.removeEventListener(eventName, handler, true);
    if (isGoogle)
      return "google";
  }

  if (document.readyState == "complete")
    detach();
  return null;
}

function isSearchResult(link)
{
  let type = isSearchPage(link.ownerDocument.defaultView);
  if (type === null)
    return false;

  if (containerAttr.hasOwnProperty(type))
  {
    let [attr, value] = containerAttr[type];
    for (let parent = link; parent; parent = parent.parentNode)
      if ("getAttribute" in parent && parent.getAttribute(attr) == value)
        return true;
  }
  return false;
}

function saveLinkTarget(event)
{
  if (!isSearchPage(event.target.ownerDocument.defaultView))
    return;

  for (currentLink = event.target; currentLink; currentLink = currentLink.parentNode)
    if (currentLink.localName == "a")
      break;

  currentLinkHref = (currentLink ? currentLink.href : null);

  // back up for propagation cancel
  setTimeout(restoreLinkTarget, 0);
}

function restoreLinkTarget(event)
{
  try
  {
    if (currentLink && currentLink.href != currentLinkHref)
      currentLink.href = currentLinkHref;
  }
  catch (e)
  {
    // Ignore due garbage collection
  }

  currentLink = currentLinkHref = null;
}

function interceptEvent(event)
{
  if (event.type == "keydown" && event.keyCode != event.DOM_VK_RETURN)
    return;

  let link = null;
  for (link = event.target; link; link = link.parentNode)
    if (link.localName == "a" || link.localName == "img")
      break;

  if (link && link.localName == "a" && isSearchResult(link) &&
      /^s*https?:/i.test(link.getAttribute("href")))
  {
    event.stopPropagation();
  }
}
// encryptedredirect.js 
chrome.webRequest.onBeforeRequest.addListener(
  function (details) {
    var requestURL = details.url;
var gurl = new RegExp('^(https?)://www.google.(?:(?!com/)[a-z]+.?[a-z]+)?/', 'i');
    return {
      redirectUrl: requestURL.replace(gurl, '$1://encrypted.google.com/')
    };
  },
  {urls: ['*://*/*']}, //
  ['blocking']
);
function checkURL(tabID, changeInfo, tab){
	if (tab.url.indexOf('encrypted.google.com') > -1) {
		chrome.pageAction.show(tabID);
	}
}
chrome.tabs.onUpdated.addListener(checkURL); 

Chrome, Opera, Vivaldi – button to extension bar to pin/unpin/open/close -> Bookmarks Bar

I’m thinking if this is possible, it quite should be. In Chromium -based browsers such as Chrome, Opera and Vivaldi Bookmarks Bar is an awesome feature – but it lacks a button in the UI to simply open/close/pin/unpin it – with a mouse or touch.

So next to omnibox on the right side of address bar is Extension Bar – could it be possible to make a simple button (browser_action) to open and close the Bookmarks Bar? No pop-up – the button itself would simply open and close the Bookmarks Bar.

Building this kind of extension… How should one proceed? Background.js?

The Bookmarks Bar is an awesome feature – but it has no open & close button! It consumes screen estate being always visible. It’s hard to find from the menus and sub menus to get the bar open. Keyboard shortcut(s) no option as there should be a graphical pin/unpin in the UI to open and close it – by mouse or touch!

So I’m thinking a button to the ext bar – is it doable? If not how about context menu? I want to resolve this matter just help me a bit to get go.