chromium/chrome/test/data/extensions/api_test/service_worker/messaging/connect_external/initiator/service_worker_background.js

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

// The extension resides in ../target/*
const kTargetExtensionId = 'pkplfbidichfdicaijlchgnapepdginl';

chrome.test.runTests([function testConnectExternal() {
  var port = chrome.runtime.connect(kTargetExtensionId);
  port.onMessage.addListener(msg => {
    console.log('{worker} initiator extension got message reply: ' + msg);
    chrome.test.assertEq('initiator->target->initiator', msg);
    chrome.test.succeed();
  });
  console.log('created port');
  port.postMessage('initiator->target');
}]);