Fired when a message is sent from another extension/app (by runtime.sendMessage). Cannot be used in a content script. chrome.runtime.onMessageExternal.addListener(function (request, sender, sendResponse){})
332976
function listener(message, sender) {
			var messageEvent = new MessageEvent({
				data: message,
				origin: sender.tab ? sender.tab.url : sender.url
			})
			if (
				('sourceChannel' in messageEvent)
				&& ('key' in messageEvent)
				&& transport.name === messageEvent.sourceChannel //events on the same channel
				&& transport.key !== messageEvent.key //skip returned back events
			) {
				handler(messageEvent)
			}
		}
437480
function sendMessage(client, to, message, callback) {
	resolveID(client, to, function(channelID) {
		client._req('post', Endpoints.MESSAGES(channelID), message, function(err, res) {
			handleResCB("Unable to send messages", err, res, callback);
		});
	});
}
246029
function receivedMessageWithoutNLP(messageText, senderID, event) {
    // match a greeting intent and send a response,
    if (messageText == "hi" || messageText == "hello") {
        sendTextMessage(senderID, "Hello there.");
    }
    // match an intent to talk to a real human
    else if (messageText == "help" || messageText == "operator") {
        // let the user know that they are being routed to a human
        sendTextMessage(senderID, "Hang tight. Let me see what I can do.");
        // send a janis alert to your slack channel
        // that the user could use assistance
        janis.assistanceRequested(event);
        
    }
    // otherwise log an unknown intent with janis
    else {
        // let the user know that the bot does not understand
        sendTextMessage(senderID, "Sorry, I don't understand.");
        // capture conversational ‘dead-ends’.
        janis.logUnknownIntent(event);
    }
}
1003268
function onPreRequestHandler (ctx, err) {
  let m = ctx._encoderPipeline.run(ctx._message, ctx);

  // encoding issue
  if (m.error) {
    let error = new Errors.ParseError(Constants.PAYLOAD_PARSING_ERROR).causedBy(m.error);
    ctx.log.error(error);
    ctx.emit('clientResponseError', error);

    ctx._execute(error);
    return;
  }

  if (err) {
    let error = null;
    if (err instanceof SuperError) {
      error = err.rootCause || err.cause || err;
    } else {
      error = err;
    }

    const internalError = new Errors.MostlyError(Constants.EXTENSION_ERROR).causedBy(err);
    ctx.log.error(internalError);

    ctx.emit('clientResponseError', error);

    ctx._execute(error);
    return;
  }

  ctx._request.payload = m.value;
  ctx._request.error = m.error;

  // use simple publish mechanism instead of request/reply
  if (ctx._pattern.pubsub$ === true) {
    if (ctx._actCallback) {
      ctx.log.info(Constants.PUB_CALLBACK_REDUNDANT);
    }

    ctx._transport.send(ctx._pattern.topic, ctx._request.payload);
  } else {
    const optOptions = {};
    // limit on the number of responses the requestor may receive
    if (ctx._pattern.maxMessages$ > 0) {
      optOptions.max = ctx._pattern.maxMessages$;
    } else if (ctx._pattern.maxMessages$ !== -1) {
      optOptions.max = 1;
    } // else unlimited messages

    // send request
    ctx._sid = ctx._transport.sendRequest(ctx._pattern.topic,
      ctx._request.payload, optOptions, ctx._sendRequestHandler.bind(ctx));

    // handle timeout
    ctx.handleTimeout();
  }
}
562487
function addEventListener(type, listener, useCapture) {
      if (type === 'DOMContentLoaded') type = 'load';
      var target = this;
      var f = function(e) {
        e._timeStamp = Date.now();
        e._currentTarget = target;
        listener.call(this, e);
        e._currentTarget = null;
      };
      this['_' + type + listener] = f;
      this.attachEvent('on' + type, f);
    }
341853
function _onMessage(message) {
        var response    = JSON.parse(message.data),
            msgRecord   = _messageCallbacks[response.id],
            callback    = msgRecord && msgRecord.callback,
            msgText     = (msgRecord && msgRecord.message) || "No message";

        if (msgRecord) {
            // Messages with an ID are a response to a command, fire callback
            callback(response.result, response.error);
            delete _messageCallbacks[response.id];
        } else if (response.method) {
            // Messages with a method are an event, trigger event handlers
            var domainAndMethod = response.method.split("."),
                domain = domainAndMethod[0],
                method = domainAndMethod[1];

            EventDispatcher.triggerWithArray(exports[domain], method, response.params);
        }

        // Always fire event handlers for all messages/errors
        exports.trigger("message", response);

        if (response.error) {
            exports.trigger("error", response.error, msgText);
        }
    }
80985
function _send(sync, messages, metaConnect, extraPath) {
        // We must be sure that the messages have a clientId.
        // This is not guaranteed since the handshake may take time to return
        // (and hence the clientId is not known yet) and the application
        // may create other messages.
        for (var i = 0; i < messages.length; ++i) {
            var message = messages[i];
            var messageId = message.id;

            if (_clientId) {
                message.clientId = _clientId;
            }

            message = _applyOutgoingExtensions(message);
            if (message !== undefined && message !== null) {
                // Extensions may have modified the message id, but we need to own it.
                message.id = messageId;
                messages[i] = message;
            } else {
                delete _callbacks[messageId];
                messages.splice(i--, 1);
            }
        }

        if (messages.length === 0) {
            return;
        }

        var url = _cometd.getURL();
        if (_config.appendMessageTypeToURL) {
            // If url does not end with '/', then append it
            if (!url.match(/\/$/)) {
                url = url + '/';
            }
            if (extraPath) {
                url = url + extraPath;
            }
        }

        var envelope = {
            url: url,
            sync: sync,
            messages: messages,
            onSuccess: function(rcvdMessages) {
                try {
                    _handleMessages.call(_cometd, rcvdMessages);
                } catch (x) {
                    _cometd._info('Exception during handling of messages', x);
                }
            },
            onFailure: function(conduit, messages, failure) {
                try {
                    var transport = _cometd.getTransport();
                    failure.connectionType = transport ? transport.getType() : "unknown";
                    _handleFailure.call(_cometd, conduit, messages, failure);
                } catch (x) {
                    _cometd._info('Exception during handling of failure', x);
                }
            }
        };
        _cometd._debug('Send', envelope);
        _transport.send(envelope, metaConnect);
    }
1004272
function onMessageCallback(data) {
        // "cancel" button is clicked
        if (data == 'PermissionDeniedError') {
            chromeMediaSource = 'PermissionDeniedError';
            if (screenCallback) {
                return screenCallback('PermissionDeniedError');
            } else {
                throw new Error('PermissionDeniedError: User rejected to share his screen.');
            }
        }

        // extension notified his presence
        if (data == 'rtcmulticonnection-extension-loaded') {
            chromeMediaSource = 'desktop';
        }

        // extension shared temp sourceId
        if (data.sourceId && screenCallback) {
            sourceId = data.sourceId;
            screenCallback(sourceId);
        }
    }
184947
function onMessage( msg ) {
	// TODO: log
	if ( msg !== null ) {
		if ( msg.opts ) {
			topical.publish( 'opts', msg.opts );
		}
		if ( msg.body ) {
			topical.publish( 'body', msg.body );
		}
	}
	run();
}
1251214
function receiveIframeMessage(event) {
    // does the origin sending the message match the current host? if not dev/null the request
    if (
      (window.location.protocol !== 'file:' &&
        event.origin !==
          window.location.protocol + '//' + window.location.host) ||
      event.data === '' // message received, but no data included; prevents JSON.parse error below
    ) {
      return;
    }

    let data = {};
    try {
      data =
        typeof event.data !== 'string' ? event.data : JSON.parse(event.data);
    } catch (e) {
      // @todo: how do we want to handle exceptions here?
    }

    if (data.event !== undefined) {
      if (data.event === 'patternLab.pageLoad') {
        // if (!urlHandler.skipBack) {
        //   if (
        //     window.history.state === undefined ||
        //     window.history.state === null ||
        //     window.history.state.pattern !== data.patternpartial
        //   ) {
        //     urlHandler.pushPattern(data.patternpartial, data.path);
        //   }

        //   /*
				// 	if (wsnConnected) {
				// 	  var iFramePath = urlHandler.getFileName(data.patternpartial);
				// 	  wsn.send( '{"url": "'+iFramePath+'", "patternpartial": "'+event.data.patternpartial+'" }' );
				// 	}
				// 	*/
        // }

        // // reset the defaults
        // urlHandler.skipBack = false;
        
      } else if (data.event === 'patternLab.keyPress') {
        if (data.keyPress === 'ctrl+shift+s') {
          goSmall();
        } else if (data.keyPress === 'ctrl+shift+m') {
          goMedium();
        } else if (data.keyPress === 'ctrl+shift+l') {
          goLarge();
        } else if (data.keyPress === 'ctrl+shift+d') {
          if (!discoMode) {
            startDisco();
          } else {
            killDisco();
          }
        } else if (data.keyPress === 'ctrl+shift+h') {
          if (!hayMode) {
            startHay();
          } else {
            killHay();
          }
        } else if (data.keyPress === 'ctrl+shift+0') {
          sizeiframe(320, true);
        }

        // @todo: chat with Brian on if this code is still used and necessary; both the `mqs` and `found` variables are both currently undefined.
        // else if (found === data.keyPress.match(/ctrl\+shift\+([1-9])/)) {
        //   let val = mqs[found[1] - 1];
        //   const type = val.indexOf('px') !== -1 ? 'px' : 'em';
        //   val = val.replace(type, '');
        //   const width = type === 'px' ? val * 1 : val * $bodySize;
        //   sizeiframe(width, true);
        // }
        // return false;
      }
    }
  }
617826
public static void sendError( String messageKey, Object[] messageArgs, ServletRequest request,
                                  ServletResponse response, Throwable cause, boolean avoidDirectResponseOutput )
            throws IOException
    {
        assert messageArgs.length == 0 || ! ( messageArgs[0] instanceof Object[] )
                : "Object[] passed to sendError; this is probably a mistaken use of varargs";

        // request may be null because of deprecated FlowController.sendError().
        if ( request != null && avoidDirectResponseOutput )
        {
            String baseMessage = Bundle.getString( messageKey + "_Message", messageArgs );
            throw new ResponseOutputException( baseMessage, cause );
        }

        // Filter the message args to prevent cross-site scripting (XSS) attacks (e.g., if one of the args is something
        // that ultimately came from the user request, and it contains something like <script>[some sscript]</script>.
        for (int i = 0; i < messageArgs.length; i++) {
            Object messageArg = messageArgs[i];
            messageArgs[i] = messageArg != null ? filterValue(messageArg.toString()) : null;
        }
        
        String html = Bundle.getString( messageKey + "_Page", messageArgs );
        response.setContentType( "text/html;charset=UTF-8" );
        response.getWriter().println(html);
        ServletUtils.preventCache( response );
    }
1019443
function onMessage(message) {
    if (done) return
    if (message.type != "utf8") return sendConnectFailed(wsConn)

    try {
      message = JSON.parse(message.utf8Data)
    }
    catch(err) {
      return sendConnectFailed(wsConn)
    }

    var id  = message.id

    if (message.type != "request") return sendConnectFailed(wsConn)
    if (message.name != "connect") return sendConnectFailed(wsConn)
    if (message.to   != "server") return sendConnectFailed(wsConn)

    var body = message.body || {}

    if (!body.key) return sendConnectFailed(wsConn)

    var session = sessions.getSession(body.key)
    var channel = channels.createChannel(session, wsConn)

    message = {
      type: "response",
      name: "connect",
      from: "server",
      id:   message.id,
      body: null
    }

    wsConn.sendUTF(JSON.stringify(message))
    cleanUp()
  }
214104
function SendMessage (auth, apiVersion) {
  if (!(this instanceof SendMessage)) return new SendMessage(auth, apiVersion)
  this._noopCallback = function () {}
  this._headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic ' + auth.basicAuth
  }
  this.versionNumber = apiVersion || 'v3'
  this.lastQueryTime = 0
  this.setContextPath()
}
135217
function onMessage(e)
    {
        if(e.data instanceof ArrayBuffer)
        {
            onArrayBuffer(e.data);
        }
        else
        {
            onStringMessage(e.data);
        }
    }
288986
public void sendMessage(BaseMessage messageOut, BaseInternalMessageProcessor messageOutProcessor)
    {
        int iErrorCode = this.convertToExternal(messageOut, messageOutProcessor);    // Convert my standard message to the external format for this message
        BaseMessage messageReplyIn = null;
        if (iErrorCode != DBConstants.NORMAL_RETURN)
        {
            String strMessageDescription = this.getTask().getLastError(iErrorCode);
            if ((strMessageDescription == null) || (strMessageDescription.length() == 0))
                strMessageDescription = "Error converting to external format";
            iErrorCode = this.getTask().setLastError(strMessageDescription);
            messageReplyIn = BaseMessageProcessor.processErrorMessage(this, messageOut, strMessageDescription);
        }
        else
        {
            Utility.getLogger().info("sendMessage externalTrxMessage = " + messageOut);

            messageReplyIn = this.sendMessageRequest(messageOut);
        }
        if (messageReplyIn != null)    // No reply if null.
        {
            this.setupReplyMessage(messageReplyIn, messageOut, MessageInfoTypeModel.REPLY, MessageTypeModel.MESSAGE_IN);
            Utility.getLogger().info("externalMessageReply: " + messageReplyIn);
            this.processIncomingMessage(messageReplyIn, messageOut);
        }
    }
490912
private void sendNotification(String errMessage, int errCode, String errType, boolean createNotification) {
        NotificationsDao notifications = storage.getNotificationsDao();
        Notification notification;

        if (errType == "warning") {
            logger.warning(errMessage); // send message to console
            if (createNotification) {
                notification = notification(WARNING_NOTIFICATION, errCode, errMessage);
                notifications.addNotification(notification);
            }
        } else if (errType == "error") {
            logger.error(errMessage); // send message to console
            if (createNotification) {
                notification = notification(ERROR_NOTIFICATION, errCode, errMessage);
                notifications.addNotification(notification);
            }
        } else if (errType == "info") {
            if (logger.isInfoEnabled()) {
                logger.info(errMessage); // send message to console
            }
        }
    }
278984
function (reason, offendingMessage) {
    var self = this;
    var msg = {msg: 'error', reason: reason};
    if (offendingMessage)
      msg.offendingMessage = offendingMessage;
    self.send(msg);
  }