This question already has an answer here:
- Can `chrome.*` extension API's be used inside content scripts? 1 answer
I am experimenting with the chrome extensions API and I ran into a problem which I don't understand,
I have a background script "background.js" and a content script "content_script.js".
background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({code:"console.log('background script')"});
chrome.tabs.executeScript({file:"javascript/content_script.js"});
});
content script
chrome.tabs.executeScript({code:"console.log('content_script')"});
The console.log in the background script works perfectly, but in the one in content_script, I get an error --> "Cannot read property 'executeScript' of undefined"
This means that I am not able to access chrome object, or the chrome.tabs object from the content script. Why is this so ?