I have a problem to pass text in input field of current opened page once button on extension popup is clicked.
When I click element with id "button" on popup nothing happens.
Here is mu manifest.js:
{
"manifest_version":2,
"name": "myextension",
"version": "1.0.0",
"browser_action": {
"default_popup": "popup.html"
},
"background": {
"service_worker": "background.js"
},
"permissions": [
"storage",
"activeTab",
"<all_urls>",
"tabs"
], "content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
]
}
content.js:
chrome.runtime.onMessage.addListener((msg, sender, response) => {
if(msg.command == "button"){
document.querySelector('input#search').value = 'miki';
console.log('sdsds');
}
return true;
});
popup.js:
document.getElementById("button").addEventListener("click", function() {
chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {command: "button"});
})
});