sitespeedio / sitespeed.io

sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your website’s speed using real browsers in various environments.
https://www.sitespeed.io/
MIT License
4.74k stars 601 forks source link

Profiling bug -- not able to to load the Salesforce page properly #3727

Closed zzhao2010 closed 9 months ago

zzhao2010 commented 2 years ago

Have you read the documentation?

URL

https://test.salesforce.com

What are you trying to accomplish

I was trying to profile a page in a Salesforce org, I was able to navigate manually or via Selenium script with either Chrome or Firefox, however the script kept falling apart at the early stage with loading issue via sitespeed.io.

Below is the script. The procedure is quite straightforward. After the preScript for logging in test.salesforce.com, navigate to a url and then do a few clicks based on xpaths in the org to test a custom feature. btw, all xpaths have been validated via Selenium script.

Most of times I received the loading error after the 120s timeout. (The loading took around 9s on average if I navigate through manually). However a few time I received "could not find the right index 0 for har for url" error instead of completely failure such that the filmstrip and snapshots were captured, but there were no performance metrics..

For debugging purposes, I also tried to profile the page that was having loading issue without the following clicks via command docker run --rm -v "$(pwd):/sitespeed.io" sitespeedio/sitespeed.io:25.11.0 --preScript sf_org_login.js https://sandbox.lightning.force.com/lightning/n/TerritoryFeedback -n 1 and it turned out that the profiling works every time just fine..

module.exports = async function (context, commands) {
  const url =
    "https://lightning.force.com/lightning/n/TerritoryFeedback";
  try {
    await commands.navigate(url);
    await commands.wait.byTime(16000);
    context.log.info(`We ended up on ${url}`);
    await commands.click.byXpathAndWait(
      "//lightning-primitive-custom-cell/button"
    );
    await commands.wait.byXpath(
      '//h1[contains(., "Child Territory_multi_2")]',
      1000
    );
    await commands.measure.start();
    await commands.click.byXpathAndWait(
      '//button[contains(., "Child Territory_multi_10")]'
    );
    await commands.wait.byXpath('//*[contains(text(),"Iorgo Shallo")]', 10000);
    return commands.measure.stop();
  } catch (e) {
    throw e;
  }
};

What browser did you use?

Chrome, Firefox

How to reproduce

As discussion with @peter in the Slack channel, there is a challenge to re-produce the issue in a public network due to the requirement of adding ip to the Salesforce org to pass through authentication if there is no secured connection available.

Relevant log output

❯ docker run --shm-size 2g --rm -v "$(pwd):/sitespeed.io" sitespeedio/sitespeed.io:25.11.0 sf_org_login.js feedback_manager_ux_enhanced_grid.js -n 1 -b firefox  --multi --spa
Google Chrome 105.0.5195.52
Mozilla Firefox 104.0
Microsoft Edge 104.0.1293.70
[2022-09-19 17:56:37] INFO: Versions OS: linux 5.10.104-linuxkit nodejs: v16.16.0 sitespeed.io: 25.11.0 browsertime: 16.15.1 coach: 7.1.2
[2022-09-19 17:56:37] INFO: Running tests using Firefox - 1 iteration(s)
[2022-09-19 17:56:39] INFO: Navigating to url https://test.salesforce.com/ iteration 1
[2022-09-19 17:57:05] INFO: Navigating to url https://d6t0000004etkeay--perf30k.sandbox.lightning.force.com/lightning/n/TerritoryFeedback iteration 1
[2022-09-19 17:57:43] INFO: We ended up on https://d6t0000004etkeay--perf30k.sandbox.lightning.force.com/lightning/n/TerritoryFeedback
[2022-09-19 17:59:45] INFO: The page did not finished loading in 120000 ms. You can adjust the timeout by setting the --maxLoadTime option (in ms).
soulgalore commented 2 years ago

Hi @zzhao2010 thanks for creating the issue and testing in both Chrome and Firefox. In sitespeed.io we have a little different configurations for Selenium than the default one, I wonder if that could be the issue? Using WebDriver you can choose when a page finished loading and when your script will get back control. In Selenium by default it waits for the unload to happen. However using that configuration there are talk going on between the browser and the webdriver that potentially adds noice. Instead we get back control direct after a navigation and configure to not run the check if the page has finished loading so often.

If you could do a try with running the same settings at Selenium that would be super helpful. You can do that by setting: --browsertime.pageLoadStrategy normal

Also another thing that differs is the script that we run to "know" when a page is finished. By default we run the script https://github.com/sitespeedio/browsertime/blob/main/lib/core/pageCompleteChecks/defaultPageCompleteCheck.js to know. I wonder if there's a some case where the onloadEventEnd do not fire?

Also is it possible for you to run the tests locally on your machine without Docker? The " "could not find the right index 0 for har for url" usually means that page actually didn't load. If you can run without using Docker you can run your test in --debug mode checkout https://www.sitespeed.io/documentation/sitespeed.io/scripting/#breakpoint. That's been very helpful for me, then I add a breakpoint and then run JavaScript directly in devtools. For example you can check that unload is really fired and you could look in the network panel and check that nothing else is going on.

soulgalore commented 9 months ago

Didn't get any feedback so closing.