This is also known as cryptojacking.
Cryptojacking is the unauthorized use of someone else’s computer to mine cryptocurrency. Hackers do this by either getting the victim to click on a malicious link in an email that loads crypto mining code on the computer, or by infecting a website or online ad with JavaScript code that auto-executes once loaded in the victim’s browser.
Its a crime and a fraud to your audience. Better to avoid it.
It`s cryptojacking only if the visitor doesn`t know that his computer is infected and mining.
It completely legal,if the people know about the browser mining script and they voluntary mine coins.
Anyway,browser mining is totally unprofitable and you need to have huge traffic to make any money with this.