Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the browser's Date/time value using chrome extension

I'm looking for a way to change the value returned from javascript's new Date() function.
In general - I'm looking for a way to write an extension that will give the user the ability to set his timezone (or diff from the time of his system's clock) without changing time/timezone on his computer.

I checked the chrome extension api but found nothing there. Will appreciate it if someone can point me at the right direction.

like image 931
Dekel Avatar asked Jun 12 '16 16:06

Dekel


People also ask

How do I change my browser timezone in Chrome?

Method 1: Using Developer Tools to Change Chrome TimezoneOpen DevTools in Chrome -> Open the Console drawer. Click on the three-dotted menu -> Click on More tools -> Sensors. From the Sensors tab, set the location according to your preference and define the specific timezone.

How do I change the date on Inspect Element?

Click the Edit Inspection button, and confirm you want to edit by clicking the OK button the alert message that appears. Use the calendar icon in the below the General Inspector comments text box on the right side of the screen to select a new return date. Then click the Save Changes button.


1 Answers

I have seen some solutions involving overriding javascript's getTime() method:

Date.prototype.getTime = function() { return [DATE + OFFSET] };

usage:

(new Date).getTime();

(source)

Apparently the time does not come from the browser but rather the operating system. So my suggestion would be to inject this javascript using a content script, and in your overriding function, you can offset the date/time by however much you would like.

like image 167
Noam Hacker Avatar answered Sep 21 '22 11:09

Noam Hacker