Search code examples
javascriptiframefingerprinting

Best way to uniquely identify a user in this case?


I am going to have code running on a site in an iframe which may or may not be cross-domain, and may be duplicated in multiple iframes. I may have code running in the top window, I may not. I want my JS to generate a unique identifier which will be the same if it is generated by my code in any iframe on that page, in multiple iframes, iframes nested in iframes, or in the top window, for the life of that load of the main page only.

It should generate the same identifier when run in any window context of that webpage loading for that user at that time. So if an iframe is removed, another one added should generate the same id.

What is the best information to use for this? It is essentially a 'session' id but needs to be generated in the browser, and be the same for any child iframe generating it. Thanks to anyone who can help!


Solution

  • After some reading, it appears making a browser fingerprint will be the solution. These github projects are helpful:

    I'll probably use one of those, or get some ideas for implementing my own simplified solution.