Once I have ever done a study. The problem I had was different from your one. But the following post may give you some idea.
Eventually, I was NOT successful. I found that the Chrome browser is very strict about security, and my test script could not trick Chrome.