Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 7265

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T02:12:12+00:00 2024-11-28T02:12:12+00:00

Create your OWN intrusive javascript blocker script πŸ›‘

  • 60k

The comment that inspired me

Recently, one of the comments on my previous article about sharing a state between windows asked me how can one go about not sharing informations about the screen to websites.

Well you can disable javascript, but nobody want that…

Another way is to make them not able to access it , but how ?

Well the solution is to use a concept I wanted to talk about : Proxies !
Stick around to find out how we're gonna do this using JS and a user script injector ( like TamperMonkey for Chrome )

Disclaimer
This is in no way a reliable way to assert that no website will be able to access screen information.
Using this on a website may break the website if the property hidden are crucial to the normal behavior of the website
This is educational content only.

Proxies

Proxies are basically a way to intercept write/read instruction to a Javascript Object.

Imagine a Person object, that has a name

type Person {     name: string }  const person: Person = {     name: "Achraf", }  
Enter fullscreen mode Exit fullscreen mode

Without a proxy, trying to get the name will of course just give back the name

Without a Proxy

But using a proxy will help us intercept this get instruction, and modify it however we want

With a proxy

Okay that sounds exactly like something we'd want !

Simple example

We'll try to make a simple anonymizer for an object that has a name

const authorAnonym = new Proxy(author, {     get(originalObject, propertyName){         if (propertyName === "name"){             return "*******"         }         return originalObject[propertyName]     } })  console.log("Original Name", author.name); console.log("Proxied Name", authorAnonym.name);  
Enter fullscreen mode Exit fullscreen mode

Result

Btw you can override more than just the get method but also set, has, etc. More Info Here

Okay that's good, but for our original purpose ( hide window properties) this wont work, as even if we create a anonimizedWindow the website will just use the original window

And….you're right. We can't use a proxy to replace the window as the window object is not replaceable , but that's okay, we'll replace other information, like the screen

Let's start writing our Script

We can start easy by overriding some information like the position of the tab on the monitor

window.screenX = 0 window.screenY = 0  window.devicePixelRatio = 0 
Enter fullscreen mode Exit fullscreen mode

Now let's make default screen properties we want to override, like for example availWidth and availHeight which are the enough to give away our monitor size

const overridenProperties: Partial<Screen> = {     availHeight: 0,     availWidth: 0,     pixelDepth: 10, }  const screenProxy = new Proxy(window.screen, {     get(screen, propertyName){         return overridenProperties[propertyName] ?? screen[propertyName]     } })  window.screen = screenProxy   
Enter fullscreen mode Exit fullscreen mode

and with that, we are basically done, let's test it on a small test website that displays information in a div

Left (without) , Right (with)

Here on the left is the website without the tamperMonkey script running and on the right with the script running !

The whole sourcecode can be found here

This was tested on Chrome only, maybe it doesn't work on mozilla, if you have, please share it in the comments !

Conclusion

Proxies are a great way to intercept read/write operation on an object, they are used for multiple reasons ( mocking dependencies, singleton pattern, caching, etc. )
If you have ideas on how to use them or personal anecdotes involving proxies, feel free to share them !

Subscribe to my Newsletter ( for free ! )

Hope you had fun reading this article , if you liked it , you can share it to your friends, you can also subscribe to my new newsletter ( first exclusive post dropping 2nd of January, don't miss it ! )
It's right here

The Degenerate Engineer | Achraf | Substack

making dumb stuff, writing about it, sometimes about tech, sometimes not. Click to read The Degenerate Engineer, by Achraf, a Substack publication. Launched 3 days ago.

favicon notachraf.substack.com

javascriptprivacytutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.