I have been exploring various resources like Stack Overflow and Google in search of an answer, but unfortunately, I haven't found anything satisfactory. Since I am still new to JavaScript, I'm feeling a bit overwhelmed.
manifest.json
{
"manifest_version": 2,
"name": "Twitch Streams List",
"description": "Discover all streams directly through Chrome",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"http://api.twitch.tv/kraken/streams?limit=20"
],
"web_accessible_resources": ["twitch.js"]
}
popup.html
<!doctype html>
<html>
<head>
<title>Acquiring top Twitch streams</title>
<style>
body {
min-width: 350px;
}
</style>
<script src="twitch.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
twitch.js
var streamGenerator = {
/* URL from which the streams are fetched */
url: chrome.extension.getURL('http://api.twitch.tv/kraken/streams?limit=20'),
/* Retrieve the streams from the specified JSON URL */
requestStreams: function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', this.url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = JSON.parse(xhr.responseText);
}
}
xhr.send();
},
/* Display the imported streams on the HTML page */
showStreams: function (e) {
var streams = resp.streams;
var output = '<ul>';
for (var i = 0; i < streams.length; i++) {
output += '<li>' + streams[i].channel.display_name + ' - ' + streams[i].channel.viewers + ' - ' + streams[i].channel.game + '</li>';
}
output += '</ul>';
console.log(output);
document.body.appendChild(output);
}
};
/* Execute the script when the popup is loaded */
document.addEventListener('DOMContentLoaded', function () {
streamGenerator.requestStreams();
});
No content appears in the popup window, and the console displays:
Failed to load resource chrome-extension://dihpppnflhlpkehcgnjggjcipffmjlgp/http://api.twitch.tv/kraken/streams?limit=20
What steps should I take to resolve this issue?
Thank you