facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.35k stars 118 forks source link

setup callback is not invoked #31

Closed KomalAgarwal1 closed 1 year ago

KomalAgarwal1 commented 1 year ago

Hi Team,

I am trying a scenario for an app which has login functionality. Used setup callback function which has login steps in the form of puppeteer script.

It's not working. Have updated the memlab version too.

Steps: page-load(baseline)[s1] > action-on-page(target)[s2] > revert(final)[s3] interaction fail, making 2 more attempt(s)...

Version: memlab@1.1.28 @memlab/heap-analysis@1.0.9 @memlab/e2e@1.0.12 @memlab/core@1.1.11 @memlab/cli@1.0.14 @memlab/api@1.0.11

Can you please help on this issue?

KomalAgarwal1 commented 1 year ago

It worked now but the flow isn't working properly. After login, it took snapshot for 1st step and then giving below error

Error Details Check timeout '/' set wait: 2000ms page-load16.2MB[s1] > action-on-page(target)[s2] > revert(final)[s3] The page is reloaded. MemLab cannot analyze heap across page reloads. Please remove window.reload() calls or disable any reload logic.

There is no reload logic written, script is as below:

function url() { return dummyurl; }

async function setup(page){ //login code}

async function action(page){ await page.goto(url1, { waitUntil: "networkidle2", });}

async function back(page){ await page.goto(dummyurl, { waitUntil: "networkidle2", });}

module.exports = { action, back, setup, url };

mrsharpoblunto commented 1 year ago

You're using page.goto which does a full page load. Memlab only works when using client-side route transitions because thats the only time when memory leaks are an issue (because if you're doing a full page load the heap gets replaced anyway, meaning no memory leaks can occur). I'd suggest replacing the page.goto calls with an interaction (i.e. clicking a button in your UI) which results in the route transition you're interested int (and if your app isn't an SPA or using client-side route transitions you might not need MemLab at all :) )

mrsharpoblunto commented 1 year ago

@JacksonGL I wonder if the error message could be made a bit more explicit to include mentioning page.goto as well.

KomalAgarwal1 commented 1 year ago

Hi @mrsharpoblunto

Thanks for the details :)

SPA apps are those which downloads every content at one go and does not creates DOM after every navigation.

But I am trying memlab on applications which downloads the content but also create DOM while a user navigate it.

So, can you please confirm if memlab will work on such types of apps?

mrsharpoblunto commented 1 year ago

(Single page apps) SPA's modify the DOM with each interaction, MPA's (multi-page apps) tear down and replace the DOM with each interaction. If your app is an MPA, you probably don't need MemLab as any memory will be cleaned up after each full page load.

JacksonGL commented 1 year ago

@KomalAgarwal1 If memlab shows the The page is reloaded. error, it means the whole JS heap has been replaced, then memlab won't be able to diff the heap change caused by your action callback.

JacksonGL commented 1 year ago

memlab has limited capability to find memory leaks from a single heap snapshot (by just looking at the final heap).

If you put all your logic including action and back into the setup callback, memlab will try to find memory leaks out of the final heap (regardless of page reloading, but you won't be able to constrain the scope of leak detection to a specific interaction)

KomalAgarwal1 commented 1 year ago

@JacksonGL and @mrsharpoblunto Thanks you for the detailed explanation.