coin-hive-stratum
coin-hive-stratum copied to clipboard
How to detect if miner is running on site in another tab
I'm looking at https://coinhive.com/documentation/miner#miner-start but I'm not really sure of how to do this properly. I'm working on a site which I want to work only if the miner is running (and not being blocked in some way), but I currently have not figured out a solution for when a user has multiple tabs open.
Right now I'm checking every second if getHashesPerSecond() > 0 and if it isn't I display a message and disable all content from being accessible. It works unless the user has two tabs. The one that is no longer mining will display this message and the page will be unusable. FORCE_MULTI_TAB
isn't really an option either because I do not want to use more than a certain percentage of the user's CPU.
Anyone have any ideas?
Another problem with isRunning()
is that even if the wasm
gets blocked isRunning()
is still true
I've worked something out with cookies by tracking each tab with an ID and then setting a variable to track which tab is mining on and it works but I'm sure it could be better. Would love to hear other ideas!
+1
the deepMiner code seems to have a bit of tab management: https://github.com/deepwn/deepMiner
@jimmy-tfp I've looked through many of the issues as well as documentation and have not found anything resembling this. Could you point me to where you saw it's tab management? Thanks!