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

How to go back to home using while loop #53

Closed Arooba-git closed 1 year ago

Arooba-git commented 1 year ago

Hi 👋 I am executing Memlab on a website locally, where the home logo's click reloads the page and goes to home URL. But since Memlab does not support reload, I figured the only way I can go back to home (the initial URL), is to page.goBack while URL !== [home URL]:

Screen Shot 2022-12-07 at 11 48 16 AM

but it runs into this error:

Screen Shot 2022-12-07 at 11 49 31 AM

I also tried this way

Screen Shot 2022-12-07 at 11 42 36 AM

but same result :/ Would apprictae any guidance/help in this regard. Cheers! ✌️

Arooba-git commented 1 year ago

Just to show the initial URL is the same as used in the conditional expression in the post:

Screen Shot 2022-12-07 at 11 57 55 AM
Arooba-git commented 1 year ago

btw I logged the URL in the loop and it seems it does reach the specified URL.. then not sure why it ends up reloading instead of terminating there 🤔

Screen Shot 2022-12-07 at 12 05 28 PM
JacksonGL commented 1 year ago

There are several different errors in on your console screenshots.

  1. The ReferenceError: addRow is not defined seems to be a bug in either Puppeteer or Chromium.
  2. When MemLab reports Error: the page is reloaded, it means MemLab found that the JavaScript heap has been cleared and reinitialized. So it means the web page under test reloads when page.goBack() is called.

To find memory leaks in MemLab, we often recommend the following test step sequence as a good practice:

A (url) -> B (action) -> A (back)

But when this is hard to achieve (like testing your web page), you don't really have to go back to the initial state. The MemLab back callback just need to make the web page reach a state where the following conditions are satisfied:

  1. The memory allocated in action are expected to be released.
  2. The JS heap is not reset (by a page reload)

So depending on the logic of the app under test,back could be navigating to a different page or triggering a different interaction, for Example, something like:

A (url) -> B (action) -> C (back)
Arooba-git commented 1 year ago

I see.. thanks for the prompt response!

btw I was wondering if it could also be due to this issue: https://github.com/puppeteer/puppeteer/issues/257

JacksonGL commented 1 year ago

Looks like a different issue since Puppeteer doesn't get stuck based on your description.