How can I trick the navigator.platform property in Safari? - Safari extension

I would like to fake the navigator.platform property in Safari so that I can make websites think I am working on a Windows architecture. I have created a Safari extension that tries to do this. The plugin simply contains an empty "global.html" file and a "spoof.js" file which is entered as a "start script" (it basically runs on every page before the content of that page is loaded). Spoof.js content:

//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 says "Windows" every time the page is loaded, 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 Guide .

The scripts injected have an implied namespace - you don't need to worry about your variable or function names conflicting with website author variable names, nor can you use author name extension functions. In other words, injected scripts and scripts included in a web page run in isolated worlds, without accessing each other's functions or data.

Does this mean that I cannot edit the navigator element with Safari extension? Is there a way to set the navigator object using an extension?

+3


source to share





All Articles