Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add try/catch in jango connector for JSON parsing on communication DIV

The change event was getting triggered when the div was still empty. The
empty string would get parsed as JSON and throw an exception.
  • Loading branch information...
commit 82447a8d50792e4eaf9db44ff96e81ba0552ccfb 1 parent b7b9968
@shamer shamer authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 jango.js
View
11 jango.js
@@ -6,9 +6,14 @@
// Used to cache the song title to prevent repeated calls to updateNowPlaying
var lastSongTitle = '';
-function updateNowPlaying(){
+function updateNowPlaying() {
var commDiv = document.getElementById('chromeLastFM');
- var songInfo = JSON.parse(commDiv.innerText);
+ try {
+ var songInfo = JSON.parse(commDiv.innerText);
+ } catch (e) {
+ // Skip malformed communication blobs
+ return;
+ }
if (songInfo['title'] == lastSongTitle) {
return;
@@ -16,7 +21,7 @@ function updateNowPlaying(){
lastSongTitle = songInfo['title'];
// Update scrobbler
- //console.log('submitting a now playing request. artist: ' + songInfo['artist'] + ', title: ' + songInfo['title'] + ', duration: ' + songInfo['duration']);
+ console.log('submitting a now playing request. artist: ' + songInfo['artist'] + ', title: ' + songInfo['title'] + ', duration: ' + songInfo['duration']);
chrome.extension.sendRequest({'type': 'validate', 'artist': songInfo['artist'], 'track': songInfo['title']}, function(response) {
if (response != false) {
chrome.extension.sendRequest({type: 'nowPlaying', 'artist': songInfo['artist'], 'track': songInfo['title'], 'duration': songInfo['duration']});

0 comments on commit 82447a8

Please sign in to comment.
Something went wrong with that request. Please try again.