-1

I want to develop chrome extension to put a check on the script say this website runs http://whatsmyscreenresolution.com/

e.g.

if (his_script==my_script) 
then 
   block it or return "123". 

I want to do something like this.Is it possible or can I even block websites to detect my screen resolution, font, etc other than disabling javascript at my end?

  • It's really hard to tell what you want. Could you clarify that, and focus on one specific aspect that's giving you trouble? – Teepeemm Jun 24 '15 at 21:56
  • See I am working on this privacy preserving chrome extension with some features. Along with those I want to add another feature that could check screen resolution script so that I am able to block it or return a false information (instead of returning 1920*1080 it says 123 or abc). I hope I am clear now ? – Zafina Khan Jun 24 '15 at 22:23
  • This question should be closed as an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Xan Jun 29 '15 at 15:29

3 Answers3

3

can I even block websites to detect my screen resolution

You could define a new window.screen object

(function (screen) {
    function clone(e) {
        var o = {}, k;
        for (k in e) o[k] = e[k];
        return o;
    }
    Object.defineProperty(window, 'screen', {get: function () {
        var o = clone(screen);
        o.availHeight = o.height = Math.random() * (o.height - 600) + 600;
        o.availWidth = o.width = Math.random() * (o.width - 600) + 600;
        return o;
    }});
}(window.screen));

After this, trying to access screen or window.screen will give you randomised (but not entirely unreasonable for styling purposes) values

DEMO

Paul S.
  • 64,864
  • 9
  • 122
  • 138
  • I might be missing something but I guess@wolfhammer is right your code is not working. This guy on https://addons.mozilla.org/en-us/firefox/addon/random-agent-spoofer/ has done all of the work which I am trying to do for chrome. My current work only spoof user agents, referer, Cookie (not Set-Cookie) but if you look at his work he can spoof all of the elements like time, screensize, via headers etc any idea how he might be changing the system level information (time, screen resolution) – Zafina Khan Jun 28 '15 at 22:43
  • @ZafinaKhan Sorry, I don't know the intricacies of what is exposed for google chrome extensions. However I do know that you'll often find FireFox based browsers expose a huge amount more than Google's one so you can't just assume something will be portable between the two. Also, after running my code I get random values, e.g. `screen.width; // 1450.2233209367841`, `screen.width; // 935.218032002449`, `screen.width; // 826.2329803034663` see [**demo here**](http://jsfiddle.net/5p0na9s0/) – Paul S. Jun 29 '15 at 02:06
  • 1
    [Isolated world](https://developer.chrome.com/extensions/content_scripts#execution-environment) problem. [Road to solution](http://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script). – Xan Jun 29 '15 at 15:26
0

Take a look at the chrome.webRequest api: https://developer.chrome.com/extensions/webRequest

Theoretically, you could do this with the onBeforeRequest listener.

Brian
  • 1,513
  • 2
  • 14
  • 17
  • Yeah I am trying to learn the API. They have mentioned "onBeforeSendHeaders" implementation but I don't find "onHeadersReceived" implementation. I also want to spoof the response e.g. Set-Cookie – Zafina Khan Jun 28 '15 at 23:15
-1

It doesn't think it's possible. Tried setting window.screen and creating a var screen but no matter what is written to screen.width and screen.height it always returns the correct resolution. It doesn't seem spoofable at least from a javascript console. You might try a hidden frame with the desired screen resolution for privacy and when the page is loaded adjust the resolution to actual browser resolution and display the frame.

wolfhammer
  • 2,641
  • 1
  • 12
  • 11