0

I need a way to sleep in javascript. Yes, I know about setTimeout and so on, but those won't do for me. I need a real sleep. One that freezes the tab or the browser. But preferably without spinning the CPU. Yes, I really, really need that. I'm sure, and I really know what I'm doing.

Of course, from a webpage that was loaded over HTTP, I could just do a synchronous GET request to /cgi-bin/sleep.sh?5000 or so (precision doesn't matter for me). However, I'm in a data URI context, so I need something more generic. I could embed a java applet and call its Thread.sleep from Javascript, I think, but I don't want to require Java. And flash doesn't seem to be able to do blocking HTTP requests.

So, does anyone know a way to sleep in a data uri context just using javascript and flash? Chromium-specific answers are ok.

I guess my reputation will go down after asking this...

thejh
  • 44,854
  • 16
  • 96
  • 107
  • +1 for `Yes, I really, really need that. I'm sure, and I really know what I'm doing.` –  Jun 30 '13 at 21:05
  • Could you explain why you really, really need sleep. I'm curious about the kind of case that would need sleep() and where setTimeout() wouldn't do it. – Aralicia Jul 01 '13 at 13:46
  • @Aralicia It's for a PoC for a security issue. I need to preserve the upper stack frames for some time. Spinning the CPU can do it, but that doesn't look so nice. – thejh Jul 01 '13 at 14:46
  • Well, I now found out that actually, in my case, synchronous GET requests would do the job, but still, that's not sooo nice for PoC code, so I'll leave this open. – thejh Jul 01 '13 at 14:46

1 Answers1

0

You need to to do that with setTimeout and a callback. There's no sleep in JavaScript.
Definitively no.
Period.

Axel Amthor
  • 10,980
  • 1
  • 25
  • 44