"Native messaging not allowed" in the browser console

I am developing an add-on which integrates with a native messaging component. Upon trying to connect, the following statement is printed in the browser console:

Native messaging not allowed: {
  "contextId": 3710851743749,
  "id": "himitsu@drewdevault.com",
  "envType": "content_child",
  "url": "http://example.org/",
  "tab": {
    "id": 13,
    "index": 6,
    "windowId": 1,
    "highlighted": true,
    "active": true,
    "attention": false,
    "pinned": false,
    "status": "complete",
    "hidden": false,
    "discarded": false,
    "incognito": false,
    "width": 1443,
    "height": 966,
    "lastAccessed": 1653562023462,
    "audible": false,
    "mutedInfo": {
      "muted": false
    },
    "isArticle": false,
    "isInReaderMode": false,
    "sharingState": {
      "camera": false,
      "microphone": false
    },
    "successorTabId": -1,
    "cookieStoreId": "firefox-default",
    "openerTabId": 6,
    "url": "http://example.org/",
    "title": "Example Domain"
  },
  "frameId": 0
}

Attempting to use the port in the add-on gives “Attempt to postMessage on disconnected port”.

I have pushed the code for my add-on here, where you may be able to reproduce the problem:

https://git.sr.ht/~sircmpwn/himitsu-firefox

The native component is just, for testing purposes, a program which copies stdin to stdout (and per my understanding would just post every message it receives back to the add-on verbatim). You can compile it with Hare, or substitute it with a similarly simple program in the language of your choice – or just use /usr/bin/cat.

I have “nativeMessaging” in my permissions in the manifest, as well as an add-on ID assigned and listed in the native component’s manifest, which I have installed at the appropriate location for Linux. I found no results when searching for the error message I received, except in the Firefox source code itself:

The issue is that native messaging is not permitted in content scripts. I moved the logic to a background script and it works. This should probably be communicated through a better error message.