Published on

How Programming Gives Us Powers Close to Superpowers

Authors
  • avatar
    Name
    Jeffer Marcelino Sunde
    Twitter

When people say you can do whatever you want if you know how to code, they are not lying. The great part about programming is being able to have an idea and bring it to life.

A Call for Help

A couple of days ago, my friend called me asking for help. His girlfriend said she lost her phone, and during the conversation, she mentioned things that made my friend suspicious about her. He started wondering if she was lying because her story didn't make any sense. So, he immediately reached out to me.

The Situation

He began telling me the story: his girlfriend was using an iPhone, but she claimed she was currently using her mom's phone, which was an Infinix. And We were trying to figure out how to determine if she was lying about having her phone stolen.

The Idea

That's when I got an idea: He could send her a link to a website, and as soon as she clicked it, we would receive the device's information to identify whether she was using an iPhone or an Android (her Mom's phone).

The website is simple; it just displays a text saying, "Do you wanna be my girlfriend?" with two buttons labeled "Yes", Both buttons redirect to his WhatsApp chat when clicked. However, to receive the device's information, it wasn't necessary for her to click anything—the mere act of opening the website would suffice.

image

Using the Navigator API

It works using the Browser API called Navigator. The Navigator API is a built-in JavaScript object that provides information about the web browser and the device running it. Key properties include:

  • navigator.userAgent: This string gives detailed information about the browser version, operating system, and device type.
  • navigator.platform: This property indicates the platform on which the browser is operating, such as Windows, macOS, iOS, or Android.
  • navigator.appVersion: This property returns the version information for the browser, including the browser name and operating system version.

Using these properties, we can gather essential information about the user's device simply by loading the website.

const userAgent = navigator.userAgent;
const platform = navigator.platform;
const appVersion = navigator.appVersion;

console.log("User Agent:", userAgent);
console.log("Platform:", platform);
console.log("App Version:", appVersion);

After collecting this information, I used my WhatsApp SDK to send the details to my personal WhatsApp:

await whatsappClient.sendTextMessage('25884xxxxxxx', 
  `User Agent: *${userAgent}*\n\nPlatform: *${platform}*\n\nApp Version: *${appVersion}*\n\n`
);

In summary, by using the Navigator API and my WhatsApp SDK, I was able to gather device information. As Uncle Ben wisely said, "With great power comes great responsibility," reminding us that with our coding abilities comes the duty to use them ethically.