question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] UnhandledPromiseRejectionWarning: TypeError: browser.newPage is not a function

See original GitHub issue

Context:

  • Playwright Version: 0.10.0
  • Operating System: Mac
  • Node: 10.15.0

Code Snippet

const { chromium, firefox, webkit } = require('playwright');

(async () => {
  const browser = await chromium.launch();  // Or 'firefox' or 'webkit'.
  const page = await browser.newPage('http://example.com');
  // other actions...
  await browser.close();
})();

Describe the bug

~/Desktop/playwright 59s
❯ node test.js
(node:38001) UnhandledPromiseRejectionWarning: TypeError: browser.newPage is not a function
    at /Users/artur/Desktop/playwright/test.js:5:30
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:38001) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:38001) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Thanks for the awesome project! Very excited about this. Stumbling into this issue after npm install playwright and trying a simple test script from the readme examples.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mmarkelovcommented, Feb 7, 2020

@arturi I suppose this is because this https://github.com/microsoft/playwright/pull/840 Cause it isn’t released yet, you should use context:

const playwright = require('playwright');

(async () => {
  for (const browserType of ['chromium', 'firefox', 'webkit']) {
    const browser = await playwright[browserType].launch();
    const context = await browser.newContext();
    const page = await context.newPage('http://example.com');
    await page.screenshot({ path: `example-${browserType}.png` });
    await browser.close();
  }
})();
0reactions
pavelfeldmancommented, Feb 8, 2020

We will be bringing back browser.newPage in 0.11, but for now please use newContext as suggested in the docs and above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodejs How to fix `browser.newPage is not a function` using ...
The problem in your code is that puppeteer works with Promises, meaning that most functions will return a Promise instead of the value ......
Read more >
browser.newPage is not a function · Issue #1326 - GitHub
It is giving me this error: findEmail error: TypeError: browser.newPage is not a function. I'm using the latest version of puppeteer.
Read more >
[TypeError] Puppeteer: `browser.newpage` is not a function
It seems to be runtime error, so it is definitely not a function in this case. Are you sure it is not undefined...
Read more >
puppeteer.Browser.newPage JavaScript and Node.js code ...
Promise which resolves to a new Page object. Most used puppeteer functions. launch. The method launches a browser instance with given arguments. The...
Read more >
TypeError: page.reload is not a function - CodeRanch
I found a fix. In your first monitor function, you didn't use await with page, so it is a promise, and promises don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found