Hi,
When using with gulp for example, it happens that you stop the process, modify your gulpfile.js, launch it again. A new tab is opened. I think there are a lot of other use cases that raise this _issue_ of multiple tabs opened on the same project.
I was wondering if it was possible to ensure that browser-sync only opens a page if it was not previously opened?
Thanks!
Hi there - great question!
Unfortunately there is not a reliable way of doing this (that I know of anyway). It's annoying, but I usually work around this by never auto-opening any browsers.
// add this line to stop any browsers opening.
open: false
Hi, thanks for the answer :smile:
I was thinking of a simple solution, tell me if I miss something.
What do you think about creating a lock file when you open a new page in the browser?
If open is called and the lock file exists, it will wait for a timeout (the same as the client poll interval).
As the client regularly polls the server, if the server receives a message during this timeout, it will only reload the existing page. If not it will open a new page.
If the lock file does not exist, it will open the page as usual.
On the client side, you could listen to the onbeforeunload event in order to detect if the tab is being closed, send a message to the server in order to remove the associated lock file.
The only caveat I see, is that when a lock file exists, the user may experience a little delay before the page is reloaded / opened.
IMHO I prefer to wait 1 second when a page already exists, rather than having to close a new tab manually.
What do you think?
Similar #84
Most helpful comment
Hi, thanks for the answer :smile:
I was thinking of a simple solution, tell me if I miss something.
What do you think about creating a lock file when you open a new page in the browser?
open
If
openis called and the lock file exists, it will wait for a timeout (the same as the client poll interval).As the client regularly polls the server, if the server receives a message during this timeout, it will only reload the existing page. If not it will open a new page.
If the lock file does not exist, it will open the page as usual.
close
On the client side, you could listen to the
onbeforeunloadevent in order to detect if the tab is being closed, send a message to the server in order to remove the associated lock file.caveat
The only caveat I see, is that when a lock file exists, the user may experience a little delay before the page is reloaded / opened.
IMHO I prefer to wait 1 second when a page already exists, rather than having to close a new tab manually.
What do you think?