facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots

Home Page:https://facebook.github.io/memlab/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Can page reload , page refresh scenarios be handled using memlab?

pranesh517 opened this issue · comments

Can we handle page reload or page refresh scenarios using memlab?
I am getting below error while running scenario:
The page is reloaded. MemLab cannot analyze heap across page reloads. Please remove window.reload() calls, page.goto() calls, or any reload logic.

I am testing login in and going back scenario.

If the web page is reloaded after login, the JS engine will create a new heap, so it doesn't make sense to revert to the pre-login scenario and compare the heap. Therefore, if the goal is to identify memory leaks during the login process and the tested web application reloads immediately after login, any memory leaks that happen during login are usually harmless as the page refresh destroys the entire heap.

However, if the goal is to find memory leaks during the initial page load following a login reload, I suggest using one of the following scenario templates without the action and back callback (memlab will try to find leaks in the entire heap without diffing the heap):

const scenario = {
  url: () => ...,  // initial page load url after the login refresh
  cookies: () => [...], // cookies for the web app under test
};
module.exports = scenario;

For more details about the cookies API, please check out the doc.

An alternative is to use beforeInitialPageLoad to log in with the Puppeteer API:

const scenario = {
  beforeInitialPageLoad: async (page) => {
    // login with username and password here
  },
  url: () => '...', // initial page load url after the login refresh
}
module.exports = scenario;

@JacksonGL: may be a lame question but, how to decide whether i should use memlab or not with any particular applications. I cam see it's only for Javascript applications. Any other constraint i should be aware of apart from Single Page Applications?

@pranesh517 Memlab can generally assist with identifying JavaScript memory leaks in single-page applications running on V8 (Chromium or Chrome) or Hermes. To get debuggable memory leak trace, the JS code needs to be non-minified (or at least minified with readable variables, function name, and property names on objects).