Get entire Playwright page in html and Text

I am using playwright in nodejs and I am having some problems when getting the page Text or Html. I just want to get the url as string like: <html><div class="123"><a>link</a>something</div><div>somethingelse</div></hmtl>

const browser = await playwright.chromium.launch({
    headless: true,
});

const page = await browser.newPage();
await page.goto(url);

I was trying to use const pageText = page.$('div').innerText; and also const pageText2 = await page.$$eval('div', el => el.innerText); But both do not work and just give me undefined.

Answer

For the full html of the page, this is what you need: const html = await page.content()

To get the inner text of the div, this should work: const pageText = await page.innerText('div')

See: