Answer the question
In order to leave comments, you need to log in
How to know what JS is running in a chrome extension?
Greetings!
My code reads chrome bookmarks.
To make it easier to develop and debug, I saved the bookmarks in a JSON file and work with it. But it is not convenient in the code to change the function that reads the bookmarks either from the file, or if it has already been installed in the browser from the browser.
Surely you can check that the JS code is being executed inside the extension, and not just the file is opened. Tell me how to do it?
That is, now I am commenting on one of the functions, but I need a condition
methods: {
getBookmarks() {
this.getBookmarksFromFile()
//this.getBookmarksFromChrome()
},
Answer the question
In order to leave comments, you need to log in
Check e.g. chrome.permissions
Outside of an extension it doesn't make sense and should be undefined.
if (window.chrome && chrome.permissions) {
//console.log('Hello from extension!');
this.getBookmarksFromChrome();
} else {
//console.log('Boring web page...');
this.getBookmarksFromFile();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question