I want to add click event to a button element which I added it dynamically within the chrome.tabs.onUpdated event function by running executeScript function.
chrome.tabs.onUpdated.addListener(() => {
chrome.tabs.executeScript(null, {file: "execute.js" });
})
I add a click event function to the dynamically added button element with this code inside executed execute.js file but it didn't work;
var btnComment=document.createElement('button');
btnComment.addEventListener('click',function(){
console.log('btnComment worked')
});
I use background.html page inside it request to background.js file. How can I implement this function?