Newbie
Newbie

Reputation: 11

PlayWright - TypeError: browser.newPage is not a function

When ever I am trying to run the code I am getting error "TypeError: browser.newPage is not a function". Here is my code

const {chromium} = require('playwright');
(async() => {
const browser = chromium.launch({
    headless:false
});
const page = await browser.newPage();
await page.goto('https://www.google.com');
await browser.close();
})();

If I change the code to the following then I am able to run the code but url is not getting open whatever I am providing, Just browser is getting open and close.

const playwright = require('playwright');
(async () => {
  for (const browserType of ['webkit']) {
    const browser = await playwright[browserType].launch({
        headless:false
    });
    const context = await browser.newContext();
    const page = await context.newPage('https://www.google.com');
    await browser.close();
  }
})();

I am using Playwright version 1.20.0 node.js version is v16.14.0

Upvotes: 0

Views: 5221

Answers (1)

Christian Baumann
Christian Baumann

Reputation: 3435

Try this

const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://www.google.com');

You might want to check out the documentation: https://playwright.dev/docs/1.19/intro#first-test

Upvotes: 1

Related Questions