简体   繁体   中英

Check if javascript library exist using chrome extension

I am making an extension and will be modifying active tab's HTML & will also inject some JS library, but before that, I want to check if certain library is already present in that tab or not, if already present then it might create problems with my injecting JS library eg;

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    chrome.tabs.executeScript(null, {file: '/javascript/angular.min.js'});
});

before injecting this I want to know if current site already have this library or not.

You don't need to do that, original js library which exists in the web page won't affect your extension.

Take a look at Execution environment ,

Content scripts execute in a special environment called an isolated world. They have access to the DOM of the page they are injected into, but not to any JavaScript variables or functions created by the page. It looks to each content script as if there is no other JavaScript executing on the page it is running on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM