I'm creating my first chrome extension and I'm having trouble calling JS functions from the html index page, I think the problem is in the background.js code, here are the components of my extension:
index.html
-------------------
<!doctype html>
<html>
<head>
<style>
html, body {
height: 80px;
width: 200px;
}
</style>
</head>
<body>
<h1>GRC</h1>
<form>
<div>
<label for="example">Veuillez saisir un code</label>
<input name="inpt" id="inpt"/>
<button id="btn" onClick="onClickHandler( document.getElementById('inpt').value )">Enter</button>
<script src="background.js"></script>
</form>
</div>
</body>
</html>
background.js
-----------------------
document.addEventListener('DOMContentLoaded', function () {
// Get button by ID
var button = document.getElementById('btn');
button.onclick = document.getElementById('inpt').value;
});
async function onClickHandler(f){
functions[f]();
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
await chrome.scripting.executeScript({
files: ['injector.js']
});
window.close();
}
injector.js
----------------
functions = {
1 : function(){alert(1);},
2 : function(){alert(2);},
3 : function(){alert(3);},
4 : function(){alert(4);},
5 : function(){alert(5);},
6 : function(){alert(6);},
}
function onClickHandler(f){
functions[f]();
}
thanks for saving me please