@@ -14,8 +14,12 @@ chrome.runtime.onConnect.addListener(function (port) {
1414 if ( i !== - 1 ) ports . splice ( i , 1 ) ;
1515 } ) ;
1616 port . onMessage . addListener ( function ( msg ) {
17- console . log ( 'Background.js Recieved Message' , msg ) ;
18- processBackgroundIncomingMessage ( msg ) ;
17+ if ( msg . tabId ) {
18+ tabInspected = msg . tabId ;
19+ getJsonResource ( tabInspected ) ;
20+ } else {
21+ console . log ( msg ) ;
22+ }
1923 } ) ;
2024} ) ;
2125
@@ -25,21 +29,13 @@ chrome.tabs.onUpdated.addListener(function (tabId, changes) {
2529 }
2630} ) ;
2731
28- function processBackgroundIncomingMessage ( msg ) {
29- console . log ( 'Processing Message in Background' , msg ) ;
30- if ( msg . tabId ) {
31- tabInspected = msg . tabId ;
32- getJsonResource ( tabInspected ) ;
33- } else {
34- console . log ( msg ) ;
35- }
36- }
37-
3832// Function to send a message to main.js
39- function notifyDevtools ( msg ) {
40- console . log ( 'Background.js Sending Message' , msg ) ;
33+ function notifyDevtools ( msgType , msg ) {
34+ var packagedMessage = { } ;
35+ packagedMessage . msgType = msgType ;
36+ packagedMessage . msg = msg ;
4137 ports . forEach ( function ( port ) {
42- port . postMessage ( msg ) ;
38+ port . postMessage ( packagedMessage ) ;
4339 } ) ;
4440}
4541
@@ -51,21 +47,22 @@ function getJsonResource(tabID) {
5147 xhr . onreadystatechange = function ( ) {
5248 var isSolidus , errMsg ;
5349 isSolidus = ( xhr . getResponseHeader ( 'X-Powered-By' ) . match ( / S o l i d u s / i) ) ;
50+ notifyDevtools ( 'info' , xhr . getResponseHeader ( 'X-Powered-By' ) ) ;
5451 if ( xhr . readyState === 4 && isSolidus ) { // Is complete Solidus response?
5552 if ( xhr . status !== 200 ) { // Check that Solidus response didn't fail
5653 errMsg = 'Failed to get Solidus context. Status: ' + xhr . status ;
57- notifyDevtools ( JSON . parse ( '{" error":"' + errMsg + '"}' ) ) ;
54+ notifyDevtools ( ' error' , errMsg ) ;
5855 } else {
5956 try {
6057 // Send Solidus JSON to devpanel
61- notifyDevtools ( JSON . parse ( xhr . responseText ) ) ;
58+ notifyDevtools ( 'context' , JSON . parse ( xhr . responseText ) ) ;
6259 } catch ( e ) {
63- notifyDevtools ( JSON . parse ( '{" error":"' + e + '"}' ) ) ;
60+ notifyDevtools ( ' error' , e ) ;
6461 }
6562 }
6663 } else {
6764 errMsg = 'Looks like you\'re not inspecting a Solidus Page.' ;
68- notifyDevtools ( JSON . parse ( '{" error":"' + errMsg + '"}' ) ) ;
65+ notifyDevtools ( ' error' , errMsg ) ;
6966 }
7067 } ;
7168 xhr . send ( ) ;
0 commit comments