facebook / memlab

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

Login functionality #16

Closed konsalex closed 1 year ago

konsalex commented 2 years ago

Hey there! Great tool, would love to give this a try, and was curious what would be the best approach to invoke a login process.

Found here the IScenario, and I'm curious if the only strategy here is the Cookie setup.

padraigfl commented 2 years ago

The page puppetter object may be able to do what you need (e.g set localStorage via page.evaluate). Haven't dug into it but the isPageLoaded parameter is presumably where you'd drop this logic.

JacksonGL commented 2 years ago

isPageLoaded might potentially do that. However, it will be called after each navigation (triggered by action and back). We can add an init(page) or setup(page) callback that is called once right after the initial page load.

konsalex commented 1 year ago

So with a simple check, if we are logged-in or not, isPageLoaded could currently do the job? That sounds good to start testing it out!

padraigfl commented 1 year ago

^ yep, I wanted to very quickly check one thing and had luck with the following, probably not very good but worked for what I wanted

async function isPageLoaded(page) {
  await page.evaluate(async () => {
    const auth = localStorage.getItem('token');
    if (!auth) {
      const token = getTokenLogicHere();
      localStorage.setItem('token', token);
      await page.refresh();
    }
  });
  return await page.evaluate(() => {
    return !!document.querySelector(loggedInElement)
  })
}