3

I would like to spoof the navigator.platform property in Safari so that I can make websites think that I am running on a Windows architecture. I created a Safari extension that attempts to do this. The plugin simply contains a blank "global.html" file and a file "spoof.js" that is injected as a "start script" (basically it executes on every page before the content of that page loads). The contents of spoof.js are:

//Copied from http://stackoverflow.com/questions/2166540/how-can-i-fool-a-site-that-looks-at-the-javascript-object-navigator-to-see-tha
new_navigator = {};
for (var i in navigator) {
    new_navigator[i] = navigator[i];
}

new_navigator.platform = 'Windows';

navigator = new_navigator;
//alert(navigator.platform);

If I uncomment the last line the alert box will say "Windows" every time I load a page, but when I test the extension using this page the website always reads the navigator.platform property as "MacIntel".

I found this excerpt in Apple's Safari extension developer's guide.

Injected scripts have an implied namespace—you don’t have to worry about your variable or function names conflicting with those of the website author, nor can a website author call functions in your extension. In other words, injected scripts and scripts included in the webpage run in isolated worlds, with no access to each other’s functions or data.

Does this mean that there is no way that I can edit the navigator item with a Safari extension? Is there any way that I can set the navigator object using an extension?

Dylan
  • 949
  • 3
  • 13
  • 23
  • Setting the UA string is not the same as setting the navigator.platform object. Check this website: http://www.w3schools.com/jsref/prop_nav_platform.asp You'll see that no matter what you set the UA string to, the platform doesn't change. – Dylan Dec 08 '14 at 06:26
  • This is an answer specifically for Chrome extensions, but since the same extension model applies, and both are WebKit-based, I think that the answer fully applies to your question: https://stackoverflow.com/questions/23202136/changing-navigator-useragent-using-chrome-extension/23456845#23456845 – Rob W Dec 11 '14 at 10:13

0 Answers0