Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close Browsers When Browser-Sync stops #1984

Closed
2 of 10 tasks
jmwebservices opened this issue Nov 16, 2022 · 1 comment
Closed
2 of 10 tasks

Close Browsers When Browser-Sync stops #1984

jmwebservices opened this issue Nov 16, 2022 · 1 comment

Comments

@jmwebservices
Copy link

Issue details

Is there a way such that all connected browsers can close when the Browser-Sync server is stopped?

Steps to reproduce/test case

Please specify which version of Browsersync, node and npm you're running

  • Browsersync [2.27.10]
  • Node [12.14.1]
  • Npm [6.13.4]

Affected platforms

  • linux
  • windows
  • OS X
  • freebsd
  • solaris
  • other (please specify which)

Browsersync use-case

  • API
  • Gulp
  • Grunt
  • CLI

If CLI, please paste the entire command below

for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync

@jmwebservices
Copy link
Author

I figured out a workaround. In my config file:

let disconnectScript = `<script>
  window.addEventListener( 'load', function()
  {
    ___browserSync___.socket.on( 'disconnect', window.close.bind( window ) );
  } );
</script>`;

module.exports = {
  snippetOptions: {
    rule: {
      fn: function( snippet, match )
      {
        return snippet + disconnectScript + match;
      },
      match: /<\/head>/i
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant