After encountering errors while using the Firebase Messaging API and attempting to send a local port, I discovered a solution that may be helpful for others facing similar issues.
If you are seeing errors like "Cannot read properties of undefined (reading 'addEventListener')" when working with the Firebase messaging API in React.js projects, one workaround is to run your local server on https rather than http. This can be achieved by running the following command:
($env:HTTPS = "true") -and (npm start)
This approach resolved the problem for me, despite triggering a privacy warning. By selecting "advanced" and proceeding, your project should now run on https://localhost:3000/ instead of http://localhost:3000/.