I needed to identify whether requests were coming from prerender.io (a library used for rendering AngularJS applications for web crawlers) or from real users. If the request was from prerender, I had to redirect to a page specifically designed for SEO purposes.
I initially tried using cookies for detection, but it didn't work because prerender.io executes JavaScript code and even cookie/session storage functions within prerender.io.
After conducting some research, I discovered that we could detect the user agent, as prerender.io calls the site in a headless browser like PhantomJS.
if (/PhantomJS/.test(window.navigator.userAgent)) {
// console.log("PhantomJS environment detected.");
} else {
// console.log("PhantomJS environment not detected.");
}
However, I wondered if this method was a permanent/proper/best solution for the issue, or if there were any alternative approaches?