Skip to content

Support Playwright locators #564

Open
@alexkreidler

Description

@alexkreidler

My code:

        console.log(`  Navigating to ${url}...`);
        await page.goto(url, { waitUntil: 'networkidle', timeout: 5000 }); // Increased timeout
        console.log(`  Navigation successful.`);

        console.log(`  Extracting body text...`);
        const text = await page.evaluate(() => {
          // Use DOM API to extract text
          const body = document.querySelector('body');
          return body ? body.innerText : '';
        });
        // const text = await page.locator('body').innerText();
        console.log(`  Text extracted (${text.length} characters).`);

        console.log(`  Saving text to ${textPath}...`);
        fs.writeFileSync(textPath, text);
        console.log(`  Text file saved.`);

Do you support Playwright locators? When I tried using const text = await page.locator('body').innerText(); I got:

  Error processing https://www.forbes.com/lists/largest-private-companies: locator.innerText: Target page, context or browser has been closed
Call log:
  - waiting for locator('body')

    at <anonymous> (/Users/al/c2/m2/test-lightpanda/screenshotter.ts:170:49)
  Closing page for https://www.forbes.com/lists/largest-private-companies...
  Closing context for https://www.forbes.com/lists/largest-private-companies...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions