This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Cuireadh an snáithe seo sa chartlann. Cuir ceist nua má tá cabhair uait.

Why is Date() constructor is unavailable in Firefox?

  • 5 fhreagra
  • 1 leis an bhfadhb seo
  • 8 views
  • Freagra is déanaí ó cor-el

more options

Am using javascript in simple web app. Works fine in Chrome, but in Firefox the Date() object type does not work. Specifically, console.log(new Date()) prints "<unavailable>" on the browser console.

Am using javascript in simple web app. Works fine in Chrome, but in Firefox the Date() object type does not work. Specifically, console.log(new Date()) prints "<unavailable>" on the browser console.

All Replies (5)

more options

Your code works in the Web Console* if I open it below this page.

<center></center>

Q: Does your app use any libraries that override or redefine the Date() constructor?


* You can open the Web Console in the lower part of the tab using either:

  • "3-bar" menu button > Web Developer > Web Console
  • (menu bar) Tools > Web Developer > Web Console
  • (Mac) Command+option/alt+k

Ref.

Athraithe ag jscher2000 - Support Volunteer ar

more options

Does not work for me. Just to simplify things, I created a tiny example that demonstrates the problem. Specifically, I created a file containing

<!doctype html5>
<html>
<script>
console.log(new Date());
</script>
</body>
</html>

and opened it as a file. In chrome, this displays the current date/time on the console. In Firefox, it shows <unavailable> on the console. Does Firefox need something more in the script to make the Date object available?

Thanks,

Athraithe ag cor-el ar

more options

Clarification to last post. The tool is removing a portion of the example file. I've been futzing around with this trying to get it to show the complete file contents, but have not figured out how to do that. So here is an explanation.

The file starts with a "doctype html5" tag, followed by an "html" tag and a "body" tag. Then comes the "script tag" and the console.log(new Date()). Then, closing versions of all tags, in the reverse order.

Hope that makes things clear.

Jon

more options

To post code here, you can replace < with &lt; so the wiki software doesn't eat your tags.

In this case, the Browser Console and the Web Console behave differently with

console.log(new Date());

The tab-specific Web Console gives you access to Date() as an object you can explore by clicking the gray triangle to the left. See my earlier screenshot. The global Browser Console does not for some reason, instead it shows "unavailable." But the Date() object is indeed instantiated. If you try

console.log(new Date().toString());

the two consoles will both display the results.

Ref.

Athraithe ag jscher2000 - Support Volunteer ar

more options

I don't know whether a website can access to console if that is what you are doing (i.e. you use this code in a website) because a website is in a sandbox when multi-process is enabled.