“browser.webRequest.onBeforeRequest” can't listen to main frame URLs after clicks

I need to listen to each HTTPS URL in the main frame and examine the URL against a pattern to check if the URL domain match a list item or not. The observer works well in the main page, e.g. https://google.co.uk. But if I tried to click any link inside the page, the loop does not terminate. It sticks in the first iteration. The console gives this error:

NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindowUtils.isParentWindowMainWidgetVisible]

This is the main.js code:
function onError(e) {
console.log(e);
}

// This function to test the intercepted URLs
function calbackFun(request) //The function will be passed request details. We use the target URL.
{
  var request = request.url;
  console.log("Request is: " + request);
  var found=false;
  var record = ["google.co.uk","facebook.com"];
  var x=0;

  for(rec of record)
  {
    console.log("loop" + x);
    var pattern = "(https:\\/\\/)(.*\\.)*"+"("+rec+")"+"(\\/.*)*(\\/)*";
    console.log("pattern is: "+pattern);
    if(request.search(pattern) == 0)
      {
        console.log("Match");
        found=true;
        break;
      }//end if

    else
      {
        console.log("No match");
      }//end else
      x++;
    }//end for

    //after the loop
    if(found == false)
    {
        console.log("no match in the whole list");
    }//end if found==flase
}//end calbackFun


browser.webRequest.onBeforeRequest.addListener(
  calbackFun, //callback function
  {urls: ["<all_urls>"],
   types: ["main_frame"]}, //urls in the main address bar
  ["blocking"]
);

This is manifest.json:
{
“manifest_version”: 2,
“name”: “testHTTPObserver”,
“version”: “1.0”,
“description”: “No description.”,
“background”: {
“scripts”: [“main.js”]
},

“applications”: {
“gecko”: {
“id”: "addon@example.com"
}
},

“permissions”: [
"<all_urls>",
“activeTab”,
“tabs”,
“storage”,
“webRequest”,
“webRequestBlocking”,
“webNavigation”
],

"browser_action": {
  "default_icon": {
    "64": "icons/warning.png"
  },
  "default_title": "testHTTPObserver"
}

}

Can you please point out to me how to resolve this issue? I need to check/examine each URL that pass through the main address bar.