chromium/chrome/test/data/webui/inject_comm_channel_2.js

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// eslint-disable-next-line no-var
var embedder = null;

function reportConnected_request() {
  const msg = ['connected_response'];
  embedder.postMessage(JSON.stringify(msg), '*');
}

window.addEventListener('message', function(e) {
  embedder = e.source;
  const data = JSON.parse(e.data);
  switch (data[0]) {
    case 'connect_request': {
      reportConnected_request();
      break;
    }
  }
});