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

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

const appName = 'com.google.chrome.test.echo';
const kExtensionURL = 'chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/';

var sentMessage = {text: 'test-echo'};
port = chrome.runtime.connectNative(appName);
port.onMessage.addListener((message) => {
  chrome.test.assertEq(sentMessage, message.echo);
  chrome.test.assertEq(kExtensionURL, message.caller_url);
  chrome.test.succeed();
});
port.postMessage(sentMessage);