I'm trying to create an extension to automate some tasks. I'm trying to load a page and then execute a code once the page has been loaded but I couldn't find the right way to do this.
custom.js:
var func=function(){
var actualCode = '(' + function() {
//load the new page
window.location='http://page.com/'
} + ')();';
// inserts the code into the current page tab
chrome.tabs.executeScript(null, { code:actualCode})
//--Execute this code once the page is loaded--
}
document.getElementById('btn').addEventListener("click",func);
index.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button id="btn"> BTN </button>
<script src="custom.js">
</script>
</body>
</html>