src/app/middlewares/api.js
function messaging(request, sender, sendResponse) {
  let tabId = getId(sender);
  if (!tabId) return;
  if (sender.frameId) tabId = `${tabId}-${sender.frameId}`;

  if (request.type === 'STOP') {
    if (!Object.keys(window.store.getState().instances.connections).length) {
      window.store.dispatch({ type: DISCONNECTED });
    }
    return;
  }
  if (request.type === 'OPEN_OPTIONS') {
    chrome.runtime.openOptionsPage();
    return;
  }
  if (request.type === 'GET_OPTIONS') {
    window.syncOptions.get(options => {
      sendResponse({ options });
    });
    return;
  }
  if (request.type === 'GET_REPORT') {
    getReport(request.payload, tabId, request.instanceId);
    return;
  }
  if (request.type === 'OPEN') {
    let position = 'devtools-left';
    if (['remote', 'panel', 'left', 'right', 'bottom'].indexOf(request.position) !== -1) {
      position = 'devtools-' + request.position;
    }
    openDevToolsWindow(position);
    return;
  }
  if (request.type === 'ERROR') {
    if (request.payload) {
      toMonitors(request, tabId);
      return;
    }
    if (!request.message) return;
    const reducerError = getReducerError();
    chrome.notifications.create('app-error', {
      type: 'basic',
      title: reducerError ? 'An error occurred in the reducer' : 'An error occurred in the app',
      message: reducerError || request.message,
      iconUrl: 'img/logo/48x48.png',
      isClickable: !!reducerError
    });
    return;
  }

  const action = { type: UPDATE_STATE, request, id: tabId };
  const instanceId = `${tabId}/${request.instanceId}`;
  if (request.split) {
    if (request.split === 'start') {
      chunks[instanceId] = request;
      return;
    }
    if (request.split === 'chunk') {
      chunks[instanceId][request.chunk[0]] = (chunks[instanceId][request.chunk[0]] || '') + request.chunk[1];
      return;
    }
    action.request = chunks[instanceId];
    delete chunks[instanceId];
  }
  if (request.instanceId) {
    action.request.instanceId = instanceId;
  }
  window.store.dispatch(action);

  if (request.type === 'EXPORT') {
    toMonitors(action, tabId, true);
  } else {
    toMonitors(action, tabId);
  }
}
function messaging(request, sender, sendResponse) {
  let tabId = getId(sender);
  if (!tabId) return;
  if (sender.frameId) tabId = `${tabId}-${sender.frameId}`;

  if (request.type === 'STOP') {
    if (!Object.keys(window.store.getState().instances.connections).length) {
      window.store.dispatch({ type: DISCONNECTED });
    }
    return;
  }
  if (request.type === 'OPEN_OPTIONS') {
    chrome.runtime.openOptionsPage();
    return;
  }
  if (request.type === 'GET_OPTIONS') {
    window.syncOptions.get(options => {
      sendResponse({ options });
    });
    return;
  }
  if (request.type === 'GET_REPORT') {
    getReport(request.payload, tabId, request.instanceId);
    return;
  }
  if (request.type === 'OPEN') {
    let position = 'devtools-left';
    if (['remote', 'panel', 'left', 'right', 'bottom'].indexOf(request.position) !== -1) {
      position = 'devtools-' + request.position;
    }
    openDevToolsWindow(position);
    return;
  }
  if (request.type === 'ERROR') {
    if (request.payload) {
      toMonitors(request, tabId);
      return;
    }
    if (!request.message) return;
    const reducerError = getReducerError();
    chrome.notifications.create('app-error', {
      type: 'basic',
      title: reducerError ? 'An error occurred in the reducer' : 'An error occurred in the app',
      message: reducerError || request.message,
      iconUrl: 'img/logo/48x48.png',
      isClickable: !!reducerError
    });
    return;
  }

  const action = { type: UPDATE_STATE, request, id: tabId };
  const instanceId = `${tabId}/${request.instanceId}`;
  if (request.split) {
    if (request.split === 'start') {
      chunks[instanceId] = request;
      return;
    }
    if (request.split === 'chunk') {
      chunks[instanceId][request.chunk[0]] = (chunks[instanceId][request.chunk[0]] || '') + request.chunk[1];
      return;
    }
    action.request = chunks[instanceId];
    delete chunks[instanceId];
  }
  if (request.instanceId) {
    action.request.instanceId = instanceId;
  }
  window.store.dispatch(action);

  if (request.type === 'EXPORT') {
    toMonitors(action, tabId, true);
  } else {
    toMonitors(action, tabId);
  }
}
function messaging ( request , sender , sendResponse ) { let tabId = getId ( sender ) ; if ( ! tabId ) return ; if ( sender . frameId ) tabId = ` ${ tabId } ${ sender . frameId } ` ; if ( request . type === 'STOP' ) { if ( ! Object . keys ( window . store . getState ( ) . instances . connections ) . length ) { window . store . dispatch ( { type : DISCONNECTED } ) ; } return ; } if ( request . type === 'OPEN_OPTIONS' ) { chrome . runtime . openOptionsPage ( ) ; return ; } if ( request . type === 'GET_OPTIONS' ) { window . syncOptions . get ( options => { sendResponse ( { options } ) ; } ) ; return ; } if ( request . type === 'GET_REPORT' ) { getReport ( request . payload , tabId , request . instanceId ) ; return ; } if ( request . type === 'OPEN' ) { let position = 'devtools-left' ; if ( [ 'remote' , 'panel' , 'left' , 'right' , 'bottom' ] . indexOf ( request . position ) !== - 1 ) { position = 'devtools-' + request . position ; } openDevToolsWindow ( position ) ; return ; } if ( request . type === 'ERROR' ) { if ( request . payload ) { toMonitors ( request , tabId ) ; return ; } if ( ! request . message ) return ; const reducerError = getReducerError ( ) ; chrome . notifications . create ( 'app-error' , { type : 'basic' , title : reducerError ? 'An error occurred in the reducer' : 'An error occurred in the app' , message : reducerError || request . message , iconUrl : 'img/logo/48x48.png' , isClickable : ! ! reducerError } ) ; return ; } const action = { type : UPDATE_STATE , request , id : tabId } ; const instanceId = ` ${ tabId } ${ request . instanceId } ` ; if ( request . split ) { if ( request . split === 'start' ) { chunks [ instanceId ] = request ; return ; } if ( request . split === 'chunk' ) { chunks [ instanceId ] [ request . chunk [ 0 ] ] = ( chunks [ instanceId ] [ request . chunk [ 0 ] ] || '' ) + request . chunk [ 1 ] ; return ; } action . request = chunks [ instanceId ] ; delete chunks [ instanceId ] ; } if ( request . instanceId ) { action . request . instanceId = instanceId ; } window . store . dispatch ( action ) ; if ( request . type === 'EXPORT' ) { toMonitors ( action , tabId , true ) ; } else { toMonitors ( action , tabId ) ; } }
Receive messages from content scripts
Receive messages from content scripts