gpt4 book ai didi

javascript - 是否可以在 headless chrome 中使用 window.performance.memory?

转载 作者:数据小太阳 更新时间:2023-10-29 05:37:55 27 4
gpt4 key购买 nike

我想使用 window.performance.memory 来测量我的 headless 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

最佳答案

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 标志才能在 headless 模式下的程序执行期间正确更新值。

关于javascript - 是否可以在 headless chrome 中使用 window.performance.memory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38087467/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com