Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. chrome.devtools.panels.create("TT's Automatron", "devtool/icon.ico", "devtool/panel.html",
  2. function(panel) {
  3.  
  4. var panelconsole;
  5.  
  6. panel.onShown.addListener(function tmp(panel) {
  7.  
  8. panel.onShown.removeListener(tmp);
  9. panelconsole = panel;
  10.  
  11. // this works
  12. chrome.runtime.sendMessage({type:'get-status'}, function(response) {
  13. panelconsole.write_queue(response.globalstatus);
  14. });;
  15.  
  16. // this does not work - cannot listen to the same messages from popup.js
  17. // as I do it in background.js
  18. chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  19. alert();
  20. });
  21. });
  22. }
  23. );
  24.  
  25. // listening to the same messages as in devtools panel
  26. chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  27.  
  28. switch(request.type) {
  29.  
  30. alert('This works');
  31.  
  32. // recognising different messages
  33. case "start-tron":
  34. // ..some code..
  35. sendResponse({globalstatus: globalstatus});
  36.  
  37. break;
  38. }
  39. });
  40.  
  41. chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  42. chrome.runtime.sendMessage({type: "start-tron", tabid:tabs[0].id});
  43. });
  44.  
  45. var port = chrome.runtime.connect({name: 'automatron_console'});
  46. port.onMessage.addListener(function(item) {
  47. // if reference exists - panel is open
  48. if (panelconsole) {
  49. panelconsole.write_log(item);
  50. }
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement