Working on library, which executes differently in different contexts/pages i.e Popup, Options, Devtools, ContentScript & Windows for which we need to know which context the library is running in and execute accordinly.
So, something like this :..
const isOptionsPage = checkForOptionsPage();
const isPopupPage = checkForPopupPage();
const isContentScript = checkForContentScript();
const isDevtools = checkForDevtools();
function myLibrary() {
if (isOptionsPage) {
// execute code for options page
//
//
} else if (isPopupPage) {
// execute code for Popup page
//
//
} else if (isContentScript) {
// execute code for Content Script
//
//
} else if (isDevtools) {
// execute code for Devtools page
//
//
}
// Common Execution
}
You'll have to infer from availability of
chromeproperties and comparelocation.hrefto the values in manifest.json.