background.js 968 B

1234567891011121314151617181920212223242526
  1. console.debug("background.js loaded");
  2. const tab_log = function(json_args) {
  3. var args = JSON.parse(unescape(json_args));
  4. console[args[0]].apply(console, Array.prototype.slice.call(args, 1));
  5. }
  6. function onMessageRequest(message, sender, sendResponse) {
  7. console.debug("background.js received request");
  8. if (message.command === 'scrub') {
  9. console.debug("background.js sending scrub message to chrome.tabs");
  10. console.debug("background.js using tabId: " + message.tabId);
  11. chrome.tabs.sendMessage(message.tabId, {command: message.command}, function(response) {
  12. sendResponse("success");
  13. });
  14. } else if (message.command === 'sendToConsole') {
  15. chrome.scripting.executeScript({
  16. target: {tabId: message.tabId},
  17. func: tab_log,
  18. args: [message.args],
  19. });
  20. sendResponse("success");
  21. }
  22. return true;
  23. }
  24. chrome.runtime.onMessage.addListener(onMessageRequest);