I wanted to detect whether request is from prerender.io(library used to render the angularjs application when request is from crawlers) or from real users.If request is from prerender, then i have to redirect to the page which is only designed for SEO purpose.
I tried setting cookies to detect but it doesn't work since prerender.io executes javascript code and even the cookie/session storage works in prerender.io.
After some research i found that we can detect user agent and since prerender.io calls site in headless browser(i.e phantomJS)
if (/PhantomJS/.test(window.navigator.userAgent)) {
// console.log("PhantomJS environment detected.");
} else {
// console.log("PhantomJS environment not detected.");
}
but is it a permanent/proper/best fix for this issue? is there any other solution?
In their FAQ, you can see the UserAgent they use:
What is your crawler's user agent?
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/61.0.3159.5 Safari/537.36 Prerender (+https://github.com/prerender/prerender)
You can use userAgent to know if the request comes from their crawler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With