【问题标题】:Is it possible to use window.performance.memory in headless chrome?是否可以在无头 chrome 中使用 window.performance.memory ?
【发布时间】:2016-10-31 10:41:30
【问题描述】:

我想使用 window.performance.memory 来衡量我在无头 chrome 测试中是否有任何内存泄漏。

在测试中:

    beforeEach(() => {
        $('body').append(initHtml);
        console.log(window.performance.memory)
    });

结果:MemoryInfo {}

在开发控制台中:

console.log(window.performance.memory)

结果: MemoryInfo {totalJSHeapSize: 27600000, usedJSHeapSize: 16100000, jsHeapSizeLimit: 1530000000}

我的 Karma.conf 包含以下内容:

browsers: ['Chrome_with_memory_tests'],
customLaunchers: {
    Chrome_with_memory_tests: {
        base: 'Chrome',
        flags: ['--enable-precise-memory-info']
    }
},

有人知道为什么会这样吗?窗口对象是可用的,因为我可以在它上面运行其他方法。也许我需要另一个标志来启用这个实验性功能? https://developer.mozilla.org/en-US/docs/Web/API/Window/performance

【问题讨论】:

    标签: javascript google-chrome performance-testing


    【解决方案1】:

    window.performance.memory 的属性不可枚举

    如果你想看到它们,你可以使用类似的东西:

    console.log(JSON.stringify(window.performance.memory, ['totalJSHeapSize', 'usedJSHeapSize', 'jsHeapSizeLimit']));
    
    // Will output something like :
    // {"totalJSHeapSize":239000000,"usedJSHeapSize":225000000,"jsHeapSizeLimit":2330000000}
    

    您确实必须启用enable-precise-memory-info 标志才能在无头模式下程序执行期间正确更新值。

    【讨论】:

      猜你喜欢
      • 2018-10-23
      • 2021-09-30
      • 2013-07-14
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-15
      • 2018-01-04
      相关资源
      最近更新 更多