I'm building a chrome extension and i got pop.js and content.js files. So far so good. But, i need to check what's the angular version of the current angular website where the extension is running. When i check the version of a specific website in console using angular.version.full command, e.g in the following website: https://angularjs.org/ , i get this version: "1.8.0". But when i try to check it through my content.js file i get this error:
Error in event handler: ReferenceError: angular is not defined at chrome-extension://mmdekcdcnkjoemkakjkbcagmgjjbdddk/content.js:19:37
Here's part of my code:
var framework = "";
var version = "";
if (document.querySelector("meta[content*='Wix.com']")) {
framework = "wix";
} else if (!!window.React ||
!!document.querySelector('[data-reactroot], [data-reactid]')) {
framework = "react";
} else if (!!window.angular ||
!!document.querySelector('.ng-binding, [ng-app], [data-ng-app], [ng-controller], [data-ng-controller], [ng-repeat], [data-ng-repeat], [ng-version]') ||
!!document.querySelector('script[src*="angular.js"], script[src*="angular.min.js"]')) {
framework = "angular";
if (document.querySelector("[ng-version]")) {
version = document.querySelector("[ng-version]").getAttribute("ng-version");
} else if (!!angular.version) { // fails here
console.log(angular.version.full)
} else {
console.log("Angular version undefiend");
}
} else {
framework = "other";
}
And I am able to access and change elements in the DOM so it's not that I misplaced it or it's not loading or something.
Does anyone have any idea why it throws an error? Thanks to all the repliers :)