如何用node.js创build一个ActiveXObject?

我在node.js是个新手。 我正在尝试使用node.js实现浏览器性能工具,所以我有以下代码:

  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(); } 

我使用httpwatch来衡量性能值,这些值将被存储在MySQL数据库中。 但是,当我运行:

 node test.js 

我得到:

 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 

我如何创build一个类似的对象作为node.js ActiveXObject和获得相同的预期结果?

https://npmjs.org/package/win32ole

尝试win32ole软件包,安装,打开node.js cmd,并input以下内容来安装软件包。

 npm install win32ole 

用法示例:

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

请看这个post: 在NodeJS中使用COM对象

我不是一个node.js用户,所以我不能专门针对node.js进行评论,但是ActiveXObject是Microsoft Active Scripting JScript引擎的function,也是IE9中新的Chakra引擎,所以它不可用在其他平台,因为它是非常特定于Windows的。

https://github.com/mynetx/codebird-js/issues/13一&#x6837; ,你可以使用xhr2来模拟它: https : xhr2

 npm install xhr2 

我不确定这是否适用于您的浏览器性能工具,但至less对于其他人使用ActiveXObject错误应该工作。