I am trying to execute javascript on a page when I click on a button in popup.html. I tried to use such a way:
In background.js:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo){
if(changeInfo.status == "loading") {
insert(tabId);
}
});
function insert(tabId) {
chrome.tabs.get(tabId, function(tab) {
$('button').click(function() {
chrome.tabs.executeScript(tab.id, {file: 'js/alert.js'});
});
});
}
Alert.js consists only of one string: alert('works');
Alert is just an example. Real script should do some DOM manipulation with opened tab after user clicks on a button im popup.html.

background.jsdoesn't meet your requirements, and seems useless. In your content script, place alert into a function, say 'handleButtonClick'. Make sure the content script is registered in the manifest. Then in the popup.html just invoke your function:chrome.tabs.executeScript({code: 'handleButtonClick()'});.