chromium/chrome/test/data/extensions/api_test/service_worker/messaging/connect_to_worker/post_message/content_script.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.

var port = chrome.runtime.connect();
port.onMessage.addListener(msg => {
  chrome.test.assertEq('tab->worker->tab', msg);
  chrome.test.succeed();
});
// Send message to extension SW which will reply back with the message
// 'tab->worker->tab'.
port.postMessage('tab->worker');