Browse Source

fix: add debugging code for messager

Gerald 8 years ago
parent
commit
e709f7aaf5
2 changed files with 7 additions and 1 deletions
  1. 1 1
      .eslintrc.js
  2. 6 0
      src/common/browser.js

+ 1 - 1
.eslintrc.js

@@ -32,7 +32,7 @@ module.exports = {
     // allow debugger during development
     // allow debugger during development
     'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
     'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
     'no-console': ['error', {
     'no-console': ['error', {
-      allow: ['error', 'warn'],
+      allow: ['error', 'warn', 'info'],
     }],
     }],
     'no-param-reassign': ['error', {
     'no-param-reassign': ['error', {
       props: false,
       props: false,

+ 6 - 0
src/common/browser.js

@@ -52,9 +52,15 @@ const meta = {
     onMessage(onMessage) {
     onMessage(onMessage) {
       function wrapListener(listener) {
       function wrapListener(listener) {
         return function onChromeMessage(message, sender, sendResponse) {
         return function onChromeMessage(message, sender, sendResponse) {
+          if (process.env.DEBUG) {
+            console.info('receive', message);
+          }
           const result = listener(message, sender);
           const result = listener(message, sender);
           if (result && typeof result.then === 'function') {
           if (result && typeof result.then === 'function') {
             result.then(data => {
             result.then(data => {
+              if (process.env.DEBUG) {
+                console.info('send', data);
+              }
               sendResponse({ data });
               sendResponse({ data });
             }, error => {
             }, error => {
               if (process.env.DEBUG) console.warn(error);
               if (process.env.DEBUG) console.warn(error);