I would like to fake Navigator platform property of CasperJS(/PhantomJS). I found the easy solutions of overwriting the Navigator Object at page load which is suggested in many other places on the web:
casper.on('page.initialized', function(){
this.evaluate(function(){
(function(oldNav){
var newNav = {};
[].forEach.call(Object.getOwnPropertyNames(navigator), function(prop){
if (prop === 'platform') {
Object.defineProperty(newNav, prop, {
value: 'Win64'
}); }else {
Object.defineProperty(newNav, prop, {
get: function(){
return oldNav[prop];
}
});
}
});
window.navigator = newNav;
})(window.navigator);
});
});
But the problem is that if we get the Navigator properties from an Iframe, the values are still the original one because, the page.initialized only set it for the main page.
So I opted to change it in its source code and build it again. I downloaded Phantomjs from the git repo, and I searched for a hardcoded platform value(Linux x86_64 for my case). I found the hardcoded string in ./phantomjs/src/qt/qtwebkit/Source/WebCore/platform/qt/UserAgentQt.cpp
I changed it to the string I wanted to be returned as the navigator.platform, but it did not affect the navigator.platform. Where should I change it? Is it(platform) a harcoded string or it is created dynamically?