javascript - 如何使用 node.js 创建一个 ActiveXObject?

标签 javascript node.js

我是 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

如何在 node.js 中创建与 ActiveXObject 类似的对象并获得相同的预期结果?

最佳答案

https://npmjs.org/package/win32ole

尝试安装 win32ole 包,打开 node.js cmd,然后键入以下内容来安装包。

npm install win32ole

示例用法:

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

另请参阅此帖子:Using COM object in NodeJS

关于javascript - 如何使用 node.js 创建一个 ActiveXObject?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16408093/

相关文章:

javascript - 如何让所有 Javascript 处理使用 JQuery .load() 加载的 html 部分

javascript - 导入用于 Typescript 类的 javascript 框架时遇到问题

node.js - azure nodejs sdk的wait()函数

javascript - NestJS:使用 JWT 向 AuthGuard 添加验证选项

node.js - Sails.js Same Model 多对多关联

javascript - 根据 D3 中的当前值更改 html 属性

javascript - 源代码中先出现的东西是否总是先渲染?

javascript - 根据用户位置查询数据库值

node.js - 找不到模块workspace/server.js

javascript - 将下拉列表转换为带有颜色的选择框并触发下拉 Action