Is it possible to use window.performance.memory in headless chrome?

I want to use window.performance.memory to measure if I have any memory leaks in my headless chrome tests.

In Tests:

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

Results in:MemoryInfo {}

In dev console:

console.log(window.performance.memory)

Results in: MemoryInfo {totalJSHeapSize: 27600000, usedJSHeapSize: 16100000, jsHeapSizeLimit: 1530000000}

My Karma.conf includes this:

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

Does anyone know why this may be? The window object is available since I can run other methods on it. Maybe I need another flag to enable this experimental feature? https://developer.mozilla.org/en-US/docs/Web/API/Window/performance

Answers:

Answer

window.performance.memory's properties are non-enumerable

If you want to see them, you may use something like:

console.log(JSON.stringify(window.performance.memory, ['totalJSHeapSize', 'usedJSHeapSize', 'jsHeapSizeLimit']));

// Will output something like :
// {"totalJSHeapSize":239000000,"usedJSHeapSize":225000000,"jsHeapSizeLimit":2330000000}

And you do indeed have to enable the enable-precise-memory-info flag to have the values be correctly updated during program execution in headless mode.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.