admin管理员组

文章数量:1188030

Is there a way in javascript or in chrome extension API to instantly (without saving the timestamp during the loading time) get the timestamp of when the DOM of the page was loaded in Chrome?

Is there a way in javascript or in chrome extension API to instantly (without saving the timestamp during the loading time) get the timestamp of when the DOM of the page was loaded in Chrome?

Share Improve this question edited Mar 4, 2014 at 15:11 Le_Coeur asked Feb 28, 2014 at 14:38 Le_CoeurLe_Coeur 1,5415 gold badges28 silver badges48 bronze badges 4
  • By timestamp you mean how long it took to load the page or when the page was last updated? – codehitman Commented Feb 28, 2014 at 14:44
  • 1 When the page was last updated/loaded – Le_Coeur Commented Feb 28, 2014 at 15:04
  • What kind of timestamp - exactly - are you looking for? Do you want a timestamp of when a specific article - say on Engadget - was last modified? If so, this is impossible. You're fully at the mercy of the data that's provided by the server about this. document.lastModified is based on the HTTP Last-Modified response header, for example. – Myrne Stol Commented Mar 4, 2014 at 12:28
  • Now you have attached a bounty, I recommend rewriting the question (and details) so it's more clear... – Myrne Stol Commented Mar 4, 2014 at 12:32
Add a comment  | 

3 Answers 3

Reset to default 19 +50

You can use the performance.timing object (implemented by all modern browsers, except Safari) to get all kinds of different timestamps.

You need to see for yourself what timestamp would be most appropriate for you. "when the page was loaded" is quite a vague description. Otherwise, be more specific.

If you don't to go through the trouble of having a Chrome content script communicate with a Chrome background page, you can also use the Chrome webNavigation API. However this only exposes events, so you'd be responsible for saving the time when this event is fired (for each page).

Click on Javascript Console from Tools menu.

Then enter the following:

 javascript:alert(document.lastModified)

Current document timestamp:

var currentDocumentTimestamp = new Date(document.lastModified).getTime();

本文标签: javascriptGet the timestamp of loaded pageStack Overflow