'beforeinstallprompt' event never fired when window.history.replaceState() is used

Howdy. Below is the simplest code by which it is obvious that the ‘beforeinstallprompt’ event is never triggered in a certain situation. The source code is:

<!doctype html> 
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <link rel="manifest" href="/manifest.json">
      <script>
         if ('serviceWorker' in navigator) {
           window.addEventListener('load', function() {
             navigator.serviceWorker.register('/sw.js').then(function(registration) {
               // Registration was successful
               console.log('ServiceWorker registration successful with scope: ', registration.scope);
             }, function(err) {
               // registration failed :(
               console.log('ServiceWorker registration failed: ', err);
             });
           });
         }

         let deferredPrompt;
         window.addEventListener('beforeinstallprompt', function(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
           console.log("beforeinstallprompt!");
         });

         // this is the line that create the problem, no matter what are the parameters
         window.history.replaceState( {}, "", "" );
         
      </script>
   </head>
   <body>
      test
   </body>
</html>

If I remove this line window.history.replaceState( {}, "", "" ) , event ‘beforeinstallprompt’ is fired and the output in console is:

ServiceWorker registration successful with scope:  https://example.com/
beforeinstallprompt!
Banner not shown: beforeinstallpromptevent.preventDefault() called. The page must call beforeinstallpromptevent.prompt() to show the banner.

If I do not remove the line window.history.replaceState( {}, "", "" ) , event ‘beforeinstallprompt’ is never fired and the output in console is:

ServiceWorker registration successful with scope:  https://example.com/

I think it’s a bug. In Chrome is working.
Can it be investigated and resolved?
Thanks.
C

This is the original post: https://stackoverflow.com/questions/69599197/samsung-internet-browser-beforeinstallprompt-event-never-fired-when-window-h

Hello @junior-root,
You can try contacting Samsung Developer Support for reporting this issue.

Issue is still present with Internet Samsung 16.2.5.4

Issue is still present with Internet Samsung 24.0.7.1

Hello,

Thank you for posting on the Samsung Developers Forums.

According to the Samsung internet team, the issue with beforeinstallprompt has been solved. You can try testing it using this website: https://mlearn-pwa-web-app-install-prompt.glitch.me/. If the issue persists in your website, please give me a website link where we can replicate the issue. I will forward it to the development team.

Sincerely,
Samiul Hossain
Samsung Developer Forums