I'm trying to get started writing chrome apps. For some reason when I view as a chrome app the javascript does not work but it works fine as a webpage. Here's the simplest instance of my issue.
opening index.html with chrome works as expected--the "hello world" string becomes "CLICK" when the button is pressed. Running as a chrome app nothing happens when the button is pressed.
manifest.json:
{
"manifest_version": 2,
"name": "My first app",
"version": "0.0.1",
"app": {
"background": {
"scripts": ["main.js"]
}
}
}
main.js
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', {
bounds: {
width: 800,
height: 609
}
});
});
index.html:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<button type="button" onclick="myFunction()">click me</button>
<script>
function myFunction(){
document.getElementById("testdiv").innerHTML = "CLICK"
}
</script>
<div id="testdiv">hello world</div>
</body>
</html>