javascript firebase notification just shows when web app is open code example

Example: import firebase cloud messaging web

import ReactDOM from "react-dom";import App from "./App";if ("serviceWorker" in navigator) {  navigator.serviceWorker    .register("./firebase-messaging-sw.js")    .then(function(registration) {      console.log("Registration successful, scope is:", registration.scope);    })    .catch(function(err) {      console.log("Service worker registration failed, error:", err);    });}ReactDOM.render(, document.getElementById("root"));