index.html

<html style="height: 100%">
 <head>
  <link rel="manifest" href="./manifest.json">
  <script src="service-worker.js"></script>
 </head>
 <body style="height: 100%; padding: 0; margin: 0">
<!-- <button type="button" id="aaa">aaaa</button>-->
<!-- <iframe src="http://localhost:8882/workflow/modeler/index.html#/processes"-->
<!--         width="100%" height="100%" frameborder="0"-->
<!-- ></iframe>-->
<!--  <div>Loading…</div>-->
  <script src="main.js"></script>
 </body>
</html>

main.js

// let deferredPrompt;
// let btnAdd = document.getElementById("aaa");
// window.addEventListener('beforeinstallprompt', (e) => {
//   // Prevent Chrome 67 and earlier from automatically showing the prompt
//   e.preventDefault();
//   // Stash the event so it can be triggered later.
//   deferredPrompt = e;
//   // Update UI to notify the user they can add to home screen
//   btnAdd.style.display = 'block';
// });
//
// btnAdd.addEventListener('click', (e) => {
//   window.location.href = 'https://chat.openai.com/chat'
//   // hide our user interface that shows our A2HS button
//   // btnAdd.style.display = 'none';
//   // // Show the prompt
//   // deferredPrompt.prompt();
//   // Wait for the user to respond to the prompt
//   // deferredPrompt.userChoice.then((choiceResult) => {
//   //   if (choiceResult.outcome === 'accepted') {
//   //     console.log('User accepted the A2HS prompt');
//   //     if (window.matchMedia('(display-mode: standalone)').matches) {
//   //       // ;
//   //     }
//   //   } else {
//   //     console.log('User dismissed the A2HS prompt');
//   //   }
//   //   deferredPrompt = null;
//   // });
// });

setTimeout(() => window.location.href="https://chat.openai.com/chat", 3000)

manifest.json

{

    "short_name": "ChatGPT",

    "name": "ChatGPT PWA",

    "start_url": "./index.html",

    "display": "standalone",

    "background_color": "#ffffff",

    "theme_color": "#ffffff",

    "icons": [

        {

            "src": "1.png",

            "sizes": "512x512",

            "type": "image/png"

        }

    ]

}

service-worker.js

if ('serviceWorker' in navigator) {
    navigator.serviceWorker
        .register('./service-worker.js')
        .then(function() { console.log('Service Worker Registered'); });
}

pwa制作-LMLPHP

03-08 16:00