how to inject javascript into a website code example
Example 1: inject javascript to webpage
$.ajax({
url: `chrome-extension://${chrome.runtime.id}/index.html`,
success: function(data){
document.getElementsByTagName('body').innerHTML += "<script id='injected'>" + data + "</script>";
},
error: function(err){
alert(err);
}
});
Example 2: how to inject javascript into html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Today's Date</title>
<script>
let d = new Date();
alert("Today's date is " + d);
</script>
</head>
<body>
</body>
</html>