Skip to content

core(user-flow): support aborting pending navigations#17067

Open
ChristopherPHolder wants to merge 4 commits into
GoogleChrome:mainfrom
ChristopherPHolder:feat/user-flow-dispose
Open

core(user-flow): support aborting pending navigations#17067
ChristopherPHolder wants to merge 4 commits into
GoogleChrome:mainfrom
ChristopherPHolder:feat/user-flow-dispose

Conversation

@ChristopherPHolder

@ChristopherPHolder ChristopherPHolder commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces a way to gracefully dispose of ongoing wait for conditions in Userflow navigation audits.

This allows programatic usage to handle failed navigations without having to await for wait for conditions to throw timeout errors.

It also automatically handles disposal of the conditions when the puppeteer page is closed.

Example usage:

import { writeFileSync } from 'fs';
import puppeteer from 'puppeteer';
import { startFlow } from 'lighthouse';

const browser = await puppeteer.launch();
const page = await browser.newPage();
const flow = await startFlow(page);

try {
  await flow.startNavigation();
  await page.goto('https://invalid-url.dev/');
  await flow.endNavigation();

  writeFileSync('report.html', await flow.generateReport());
} catch (error) {
  flow.dispose();
  console.error(error);
}

await browser.close();

Related Issues/PRs

CLOSES: #17065

@ChristopherPHolder ChristopherPHolder requested a review from a team as a code owner June 7, 2026 10:33
@ChristopherPHolder ChristopherPHolder requested review from connorjclark and removed request for a team June 7, 2026 10:33
@ChristopherPHolder ChristopherPHolder marked this pull request as draft June 7, 2026 10:34

@connorjclark connorjclark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks promising!

could you also add something to docs/user-flows.md (perhaps under tips and tricks) about dispose()?

};
});

/** @type {(event: Event) => void} */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice was not aware of that API.

I implemented the changes.

But I am not super sure it make sense tho, if a user calls dispose the navigation is will simply cancel the wait for conditions.

A user is not able to call startNavigation if the last navigation was not cleanedup successfully. That throws a clear error.


On a seperate note, i have phased another issue in the past where the audit took extremely long because the page was polling. So the network and cpu were never really quiet.

In theory i can dispose of the await conditions when i see the element i want render on the page.

Kind of an abuse of the api tho...

Those things are edge cases and probably better to move forward and i open another issue if it becomes an issue again.

@ChristopherPHolder ChristopherPHolder changed the title feat(user-flow): support aborting pending navigations core(user-flow): support aborting pending navigations Jun 9, 2026
@ChristopherPHolder ChristopherPHolder force-pushed the feat/user-flow-dispose branch 2 times, most recently from cca3eef to d684e5c Compare June 9, 2026 11:19
@ChristopherPHolder ChristopherPHolder marked this pull request as ready for review June 9, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve cleanup flow for programmatic usage

2 participants