chromium/chrome/test/data/extensions/api_test/service_worker/messaging/connect_to_worker/connect/content_script.js

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

// Store the port to prevent it from garbage collection, which may result
// in closing the port.
window.port = chrome.runtime.connect();
window.port.onMessage.addListener(msg => {
  chrome.test.succeed();
});