Skip to content

Let a caller that already navigated collect the CSS of the page #5

Closed

Description

@nucliweb

Hi Bart! Joan here. I'm planning a CSS analysis for the CLI of WebPerf Snippets with css-analyzer, and I'd rather use css-scraper than write another collector. The design principles in the README are exactly what we need, especially preferring the shipped text over the CSSOM.

One thing gets in the way: scrape_css(page, url) calls page.goto() itself. Our CLI navigates on its own (CPU and network throttling, request headers, a storage state for pages behind a login, scripted interactions), and a second load would measure a different page.

The steps already exist in network-css.ts and dom-css.ts; only scrape_css is exported. Would you accept exporting them, so a caller can start tracking before its own navigation and collect afterwards? Something like:

import { track_css_responses, collect_css } from '@projectwallace/css-scraper'

const responses = track_css_responses(page)
await page.goto(url) // or whatever the caller does to load the page
const sources = await collect_css(page, responses)

collect_css would be the second half of scrape_css (collect_dom_css plus cross_check_network_responses), and scrape_css would become track, goto, collect, with no change for current users. The names are yours to pick, of course.

If the shape works for you, I'm happy to send a PR with tests. I also noticed two small things in the usage example of the README: the import reads @projectwallace/scrape-css instead of @projectwallace/css-scraper, and the last line reads css.source.css instead of css_source.css. I can fix them in the same PR or in a separate one, whichever you prefer.

Activity

  1. bartveneman commented on Nov 2, 2026

    @bartveneman
    Member

    Heeey, sorry, I missed the notification for this one. I really dig the idea and I think the API design is better that way, so I made it the default in the readme and exposed the API's as you suggested. Marked you as co-author of the commit in #8. Thanks for the great suggestion! Is the PR what you had in mind?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions