Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate alternatives for Puppeteer usage #147

Open
whimboo opened this issue Oct 6, 2022 · 2 comments
Open

Investigate alternatives for Puppeteer usage #147

whimboo opened this issue Oct 6, 2022 · 2 comments

Comments

@whimboo
Copy link

whimboo commented Oct 6, 2022

Follow-up from the discussion on #146.

It would be good to know for what exactly Puppeteer is needed and if it could be replaced with something else that doesn't have a strict requirement for a given browser.

@sidvishnoi maybe you could please explain? I'm happy to help on this issue.

@OrKoN
Copy link

OrKoN commented Oct 6, 2022

@whimboo what's the use case? We could use puppeteer with WebDriver BiDi + Firefox if you need basic JS evaluation to a basic type.

@sidvishnoi
Copy link
Member

Puppeteer is used in following cases presently:

  1. Getting processed shortname from ReSpec document (after JS evaluation):
    const shortName: string = await page.evaluate(
    // @ts-ignore
    () => window.respecConfig.shortName as string,
    );
    console.log("[INFO] shortName:", shortName);
    return shortName;
  2. Extracting bikeshed metadata pre.metadata to get shortname:
    const text = await readFile(source.path, "utf8");
    const metadata = await page.evaluate((text: string) => {
    const doc = new DOMParser().parseFromString(text, "text/html");
    return doc.querySelector("pre.metadata")?.textContent || null;
    }, text);
    if (!metadata) {
    throw new Error("Failed to read metadata");
    }
    const config = getConfigOverride(metadata)!;
    // Bikeshed allows metadata keys to be in any case: Shortname/shortName etc.
    const shortnameKey = Object.keys(config).find(
    key => key.toLowerCase() === "shortname",
    );
    if (!shortnameKey || !config[shortnameKey]) {
    throw new Error("No `shortname` found in metadata");
    }
    const shortName = config[shortnameKey];
    console.log("[INFO] shortName:", shortName);
    return shortName;
  3. Some query selector processing to extract metadata from published pages:
    const thisURI = await page.$$eval("body div.head dl dt", elems => {
    const thisVersion = (elems as HTMLElement[]).find(el =>
    /this (?:published )?version/i.test(el.textContent!.trim()),
    );
  4. Full page content parsing, JS/CSS evaluation with subresources to extract all directly and indirectly referenced assets from a page that need to be copied for deployment:
    async function findAssetsToCopy(source: Input["source"]) {

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

No branches or pull requests

3 participants