I need some help with my code. Im trying to messaging from background.js to content-script on web-page but something got wrong
manifest.json
{
"name": "Fill my password",
"version": "1.0",
"manifest_version": 2,
"description": "Fills my password on University login page",
"background":
{
"scripts": ["background.js"]
},
"permissions": ["tabs", "<all_urls>", "contextMenus"],
"content_scripts": [
{
"matches": ["https://www.binary.com/ru/trading.html?currency=AUD&market=volidx&underlying=R_10&formname=risefall&date_start=now&duration_amount=1&duration_units=m&amount=10&amount_type=payout&expiry_type=duration"],
"js": ["content.js"]
}]
}
content.js
{
var loginForm = document.getElementById('btn_login');
chrome.extension.onMessage.addListener(function (msg, sender, sendResponse) {
alert("Message recieved!");
if (msg.action == "open_dialog_box") {
loginForm.click();
alert("Message recieved!");
}
});
}
background.js
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var time = new Date();
secondsRemaining = (60 - time.getSeconds()) * 1000;
setTimeout(
function () {
chrome.tabs.sendMessage(tabs[0].id, { action: 'open_dialog_box' },
alert('response'))
}, 5000
)
})
Thanks for your help!