Firefox extension only works when refreshing [duplicate]

  firefox-webextensions, javascript

I’m trying to make an extension for firefox which blocks you for clicking on youtube links.
What I want is to get the url of the youtube link and then use history.back to redirect the client.
But when I’m trying to test my extension via about:debugging, it works only when a youtube link is already opened and it sets me to a new tab once.
The only error I get is SecurityError: Permission denied to access property "windowGlobalChild" on cross-origin object.
Heres’s my manifest.json :

{ [...],
"content_scripts": [
      "matches": ["*"],
      "js": ["youtubefox.js"]

And here my javascript :

var url = window.location.href;
function goBack() {

Source: Ask Javascript Questions