Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6470591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:07:44+00:00 2026-05-25T06:07:44+00:00

I currently set up EnvJS on my system (installed from here ). My end

  • 0

I currently set up EnvJS on my system (installed from here).
My end goal is to load a page let it’s javascript process for a few seconds, and then read the dom to get the information of interest. However I can not get setTimeout() to work to save my life (Or JQuery for that matter).

I have a php script that starts the process:

...
$ENVJS_PATH = "/var/www/project/src/envjs";
$RHINO_JAR = "rhino/js.jar";
$INIT_SCRIPT = "init.js";
$output = shell_exec("java -jar $ENVJS_PATH/$RHINO_JAR -opt -1 $ENVJS_PATH/$INIT_SCRIPT");
echo "Response from javascript:<br/> $output";
...

the init.js file looks like:

load('/var/www/project/src/envjs/dist/env.rhino.js');
print("Loaded env.rhino.js<br/>");

// temporarily commented out
//var url = "http://www.ken-soft.com";
//window.location = url;
//print("<br/>Loaded "+url+"<br/>");

// Problem starts here
var runAfterPause=function() {
  print("got here..."); // never gets called
  print(document.getElementById('some_id').innerHTML);
}
setTimeout(runAfterPause, 3000); //wait three seconds before continuing
// i have also tried setTimeout("runAfterPause()", 3000);
print("<br/>End<br/>");

Any knowledge on this would be much appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:07:45+00:00Added an answer on May 25, 2026 at 6:07 am

    Try env.rhino.1.2.js – and if the server OS hosting rhino is Ubuntu, then try sudo apt-get install rhino — and call rhino -opt -1 ... instead of java -jar ...

    Seems to run like this for me on Ubuntu 11.04, when ran directly on the shell – not sure if PHP’s shell_exec may influence things or not..

    EDIT: Indeed it is not really working; I looked through the source a bit, and could see that setTimeout relies on Timer.prototype.start = function(){};, which is apparently empty. Browsing further, the only thing that seems to deal with timing is Envjs.wait() – and using that, I can finally get a sort of a timed loop; however, note that it seems to be strictly single-threaded (synchronous) now:

    print("loading " + 1.2);
    load('env.rhino.1.2.js'); // takes a while ...
    print("loaded " + 1.2);
    console.log(window);
    
    var c=0;
    function timedCount() // like this, when setTimeout calls a string!
    {
      c=c+1;
      print("c=" + c);
    
      if (c<10) // make a limit for the run of script:
      {
        var t;
        //~ t=window.setTimeout(timedCount(),100); // TypeError: fn is not a function, it is undefined.
        t=window.setTimeout("timedCount()",1000); // must have `t=...` - else it locks on return even w/ wait(0)!
        Envjs.wait(); // waits, but "timer error  undefined   TypeError: fn is not a function, it is undefined." if setTimout doesn't call string; wait(0) exits immediately
      } else Envjs.wait(0); // "reset": execute all timers and return; else here will be left hanging from previous wait()
    }
    
    
    
    // main:
    
    timedCount();
    //~ eval("timedCount()", null); // works the same
    
    print("after timedCount()");
    

    … and the results are:

    $ sudo apt-get install rhino
    $ wget https://github.com/thatcher/env-js
    
    $ rhino -opt -1 test.js
    loading 1.2
    [  Envjs/1.6 (Rhino; U; Linux i386 2.6.38-11-generic; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13  ]
    loaded 1.2
    [Window]
    a
    c=1
    c=2
    c=3
    c=4
    c=5
    c=6
    c=7
    c=8
    c=9
    c=10
    after timedCount()
    

    If I recall correctly, in a browser setInterval is asynchronous/multithreaded – indeed, in a browser JavaScript Shell 1.4, the almost same code:

    var c=0;
    function timedCount() 
    {
      c=c+1;
      print("c=" + c);
    
      if (c<10)  {
        var t;
        t=window.setTimeout("timedCount()",1000); 
      }
    }
    
    timedCount();
    print("after timedCount()");
    

    produces:

    c=1
    after timedCount()
    c=2
    c=3
    c=4
    c=5
    c=6
    c=7
    c=8
    c=9
    c=10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a scenario: I have a java front end (RCP/SWT) app which currently has
I'm creating my first game, and I've currently set up a 'GameState' class, to
I currently have speakers set up both in my office and in my living
I've currently got a set of reports with a number of common functions sitting
I am currently trying to set up a new visual studio 2008 solution while
Currently I have subversion set up so that when I make changes in Eclipse
I currently have CruiseControl.NET set up with SVN to automatically grab the code source
Currently I have a root-level repository set up for each project, like so: Project1
I currently have my code set to disable the submit button when the field
Currently I have a site that is set up using a masterpage and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.