33// Can use:
44// chrome.tabs.*
55// chrome.extension.*
6+
67var tabInspected ;
78var ports = [ ] ;
89chrome . runtime . onConnect . addListener ( function ( port ) {
@@ -18,14 +19,14 @@ chrome.runtime.onConnect.addListener(function (port) {
1819 } ) ;
1920} ) ;
2021
21- chrome . tabs . onUpdated . addListener ( function ( tabId , changes , tabObject ) {
22- if ( tabId == tabInspected && changes . status == "complete" ) {
22+ chrome . tabs . onUpdated . addListener ( function ( tabId , changes ) {
23+ if ( tabId === tabInspected && changes . status = == "complete" ) {
2324 getJsonResource ( tabId ) ;
2425 }
2526} ) ;
2627
2728function processBackgroundIncomingMessage ( msg ) {
28- console . log ( "Processing Message in Background" , msg )
29+ console . log ( "Processing Message in Background" , msg ) ;
2930 if ( msg . tabId ) {
3031 tabInspected = msg . tabId ;
3132 getJsonResource ( tabInspected ) ;
@@ -43,26 +44,26 @@ function notifyDevtools(msg) {
4344}
4445
4546function getJsonResource ( tabID ) {
46- var pageContext ;
4747 chrome . tabs . get ( tabID , function ( tab ) {
4848 var jsonResourceURL = tab . url + ".json" ;
4949 var xhr = new XMLHttpRequest ( ) ;
5050 xhr . open ( "GET" , jsonResourceURL , true ) ;
5151 xhr . onreadystatechange = function ( ) {
52- if ( xhr . readyState === 4 && xhr . getResponseHeader ( "X-Powered-By" ) . substring ( 0 , 7 ) === "Solidus" ) {
53- if ( xhr . status === 200 ) { //Check this separately so we can notify devtools if we don't get a 200 response.
52+ var isSolidus = ( xhr . getResponseHeader ( "X-Powered-By" ) . substring ( 0 , 7 ) === "Express" ) ;
53+ if ( xhr . readyState === 4 && isSolidus ) { // Check for completed Solidus response
54+ if ( xhr . status !== 200 ) { // Check that Solidus response didn't fail
55+ notifyDevtools ( JSON . parse ( '{"error":"Failed to get Solidus page context."}' ) ) ;
56+ } else {
5457 try {
5558 notifyDevtools ( JSON . parse ( xhr . responseText ) ) ;
5659 } catch ( e ) {
5760 notifyDevtools ( JSON . parse ( '{"error":"' + e + '"}' ) ) ;
5861 }
59- } else {
60- notifyDevtools ( JSON . parse ( '{"error":"Solidus Page Context Not Found!"}' ) ) ;
6162 }
6263 } else {
6364 notifyDevtools ( JSON . parse ( '{"error":"Looks like you\'re not inspecting a Solidus Page."}' ) ) ;
6465 }
65- }
66+ } ;
6667 xhr . send ( ) ;
6768 } ) ;
6869}
0 commit comments