I have a webpage that has custom events that I would like to listen to with a chrome extension. Every time an order comes in, the webpage gets the order and updates a little notification number with how many orders are pending. I am looking to create a chrome extension to listen to this event and in future be able to select the order and perform actions on it.
First of all, is this possible?
In the website source code that I found through using F12 on Chrome I found the orderHandler.js file
var OrdersHandler=new(function(){this.getOrder=function(item_id,success,fail){try{$.ajax({url:'/api/orders/'+item_id,method:"GET",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.getOrdersList=function(listName,success,fail){try{$.ajax({url:'/api/orders-list/'+listName,method:"GET",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_items);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.getOrderItem=function(item_id,success,fail){try{$.ajax({url:'/api/order_items/'+item_id,method:"GET",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.takeOrderItem=function(item_id,success,fail){try{$.ajax({url:'/api/order_items/'+item_id+"/take",method:"POST",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.reprocessOrderItem=function(item_id,success,fail){try{$.ajax({url:'/api/order_items/'+item_id+"/reprocess",method:"POST",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.setSupplierOrderItem=function(item_id,supplier_id,success,fail){try{$.ajax({url:'/api/order_items/'+item_id+"/change_supplier",method:"POST",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token,"Content-Type":"application/json"},data:JSON.stringify({supplier_id:supplier_id}),success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.releaseOrderItem=function(item_id,success,fail){try{$.ajax({url:'/api/order_items/'+item_id+"/release",method:"POST",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.setOrderItemEarnPrice=function(item_id,price,success,fail){try{$.ajax({url:'/api/order_items/'+item_id,method:"PATCH",data:JSON.stringify({earn_price:price}),headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token,"Content-type":"application/json"},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.confirmOrderItemDelivered=function(item_id,success,fail){try{$.ajax({url:"/api/order_items/"+item_id+"/confirm_delivered",method:"POST",headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.markOrderItemDelivered=function(item_id,delivery_proof,files,success,fail){try{$.ajax({url:"/api/order_items/"+item_id+"/mark_delivered",method:"POST",data:JSON.stringify({delivery_proof:delivery_proof,files:files}),headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token,"Content-type":"application/json"},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response.order_item);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};this.addChatMessage=function(item_id,message,success,fail){if(message.length<3){return;}
try{$.ajax({url:'/api/order_items/'+item_id+"/chats",method:"POST",data:JSON.stringify({message:message}),headers:{"Authorization":"Bearer "+Cookies.getJSON("access_token").access_token,"Content-type":"application/json"},success:function(response,status,xhr){if(response.success){if(typeof(success)=="function"){success(response);}}
else{if(typeof(fail)=="function"){fail(status,response.message);}}},error:function(response,status,statusName,xhr){if(typeof(fail)=="function"){if(typeof(response.responseJSON)==="object"&&typeof(response.responseJSON.message)==="string"){fail(response.status,response.responseJSON.message);}
else{fail(response.status,response.status==0?"Network error":statusName);}}}});}
catch(e){console.log(e);onFailure(-1,"Script error");}};})();
A lot of the Handler seems to be failure cases and what message to output depending on that. I was having a hard time deciphering what it is doing and how I can make a background.js to listen to the getOrder function.
Any help with these would be greatly appreciated! Ask for any clarification in the comments!
UPDATE
Via the helpful comments below. I can see that the window.OrdersHandler has functions available
Are these functions usable and how would I connect this to a Listener? chrome.runtime.addListener()?