I am creating for the first time a browser extension.
I created my popup, which contains different buttons that should trigger javascript functions. Except that when I click on a button, nothing happens.
popup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<button id="test">Test</button>
</div>
<script src="js/popup.js"></script>
</body>
</html>
js/popup.js
function save() {
console.log('I save !!');
}
// I tried :
document.getElementById('test').innerHTML = 'TOTO'; => KO
document.getElementById('test').addEventListener('click',
save); => KO
document.getElementById('test').click(function () {
save();
}); => KO
manifest.json
{
"manifest_version": 3,
"name": "name of extension",
"version": "2.0",
"description": "Description about extension",
"icons": {
"512": "images/lbo_favicon.png"
},
"default_locale": "en",
"action": {
"default_title": "Click Me",
"default_popup": "popup.html"
},
"commands": {
"_execute_action": {
"suggested_key": {
"windows": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y",
"chromeos": "Ctrl+Shift+Y",
"linux": "Ctrl+Shift+Y"
}
}
}
}
No reaction, no error in console either.
How can I get my clicks in the popup to be taken into account by my javascript ?
Thank you.