7

I'm a totally newbie in node.js. I'm trying to implement a browser performance tool using node.js, so I have the following piece of code:

 for(var j=0; j < 14; j++) {
        // Create a new instance of HttpWatch in Firefox
        var control = new ActiveXObject('HttpWatch.Controller');
        var plugin = control.Firefox.New();
        // Start Recording HTTP traffic
        plugin.Log.EnableFilter(false);
        // Clear Cache and cookier before each test
        plugin.ClearCache();
        plugin.ClearAllCookies();   
        plugin.ClearSessionCookies();
        plugin.Record();
        // Goto to the URL and wait for the page to be loaded
        plugin.GotoURL(url);
        control.Wait(plugin, -1);
        // Stop recording HTTP
        plugin.Stop();
        if ( plugin.Log.Pages.Count != 0 )
        {           
           // Display summary statistics for page
           var summary = plugin.Log.Pages(0).Entries.Summary;
           //WScript.Echo( "Iteration number " + j + "for" + url + "   Total time to load page in (secs): " + summary.Time);
           cache[i].value.push(summary.Time);
        }
        // Close down Firefox
        plugin.CloseBrowser();
      }

I'm using httpwatch to measure the performance values, which are going to be stored in a MySQL database. However, when I run:

node test.js

I get:

C:\xampp\htdocs\test\browser-perf>node test.js

C:\xampp\htdocs\test\browser-perf\test.js:37
                var control = new ActiveXObject('HttpWatch.Controller');
                                  ^
ReferenceError: ActiveXObject is not defined
    at Object.<anonymous> (C:\xampp\htdocs\test\browser-perf\test.
js:37:21)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

How can I create a similar object as ActiveXObject in node.js and obtain the same desired results?

cybertextron
  • 10,547
  • 28
  • 104
  • 208

3 Answers3

12

https://npmjs.org/package/win32ole

try the win32ole package, to install, open the node.js cmd, and type the following to install the package.

npm install win32ole

Example usage:

var win32ole = require('win32ole');
var xl = win32ole.client.Dispatch('Excel.Application');
xl.Visible = true;

Please also see this post: Using COM object in NodeJS

justyy
  • 5,831
  • 4
  • 40
  • 73
1

I'm not a node.js user, so I can't comment on node.js specifically, but ActiveXObject is a feature of the Microsoft Active Scripting JScript engine, as well as the new Chakra engine in IE9, so it is not available in other platforms because it's very Windows-specific.

Dai
  • 141,631
  • 28
  • 261
  • 374
1

As in https://github.com/mynetx/codebird-js/issues/13, you can emulate it using xhr2: https://npmjs.org/package/xhr2.

npm install xhr2

I'm not sure if that will work for your browser performance tool but at least for someone else googling on the ActiveXObject error it should work.

isomorphismes
  • 8,233
  • 9
  • 59
  • 70