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] (Browser.newPage): target is undefined

See original GitHub issue

Context:

Hi Guys. I spent the last two days trying to deploy a Node.js app with Playwright library to Heroku. The code works fine in my local environment, but it failed in Heroku with the error message target is undefined. The website I’m trying to scrape is really heavy, and it took 10 seconds to run the following function locally. And only the waitUntil: "networkidle" option would work locally. I tried to disable timeout, but no luck there.

I wonder if it’s a Memory or CPU issue? Heroku Free tier only has 512MB in RAM.

If Heroku doesn’t work, any other hosting site would work? I also attempted to use firebase but didn’t get far.

Code Snippet

const { firefox } = require("playwright-firefox");

module.exports = async function scrapeAPI(url) {
  const result = [];
  try {
    if (url) {
      const browser = await firefox.launch({ chromiumSandbox: false });
      const context = await browser.newContext();
      const page = await context.newPage();
      page.route(/.*[some api route].*/, (route) => {
        route
          .request()
          .response()
          .then((response) => {
            response
              .body()
              .then((b) => {
                const arr = JSON.parse(b.toString());
                result.push(...arr);
              })
              .catch((err) => {
                throw err;
              });
          });
        route.continue();
      });

      await page.goto(url, {
        waitUntil: "networkidle",
        timeout: 0,
      });
      await browser.close();

      return result;
    } else {
      throw new Error("url doesn't exisit");
    }
  } catch (e) {
    console.error({ 
      message: "scrapeAPI failed", 
      e, 
      resultLength : result.length,
    });
    throw e;
  }
};

Describe the bug

error:

message: 'unable to get availiability',
e: browserContext.newPage: Protocol error (Browser.newPage): target is undefined newPage@chrome://juggler/content/TargetRegistry.js:307:5
at Connection.sendMessageToServer (/app/node_modules/playwright-firefox/lib/client/connection.js:69:15)
at Proxy.<anonymous> (/app/node_modules/playwright-firefox/lib/client/channelOwner.js:44:61)
at /app/node_modules/playwright-firefox/lib/client/browserContext.js:95:58
at BrowserContext._wrapApiCall (/app/node_modules/playwright-firefox/lib/client/channelOwner.js:72:34)
at BrowserContext.newPage (/app/node_modules/playwright-firefox/lib/client/browserContext.js:92:21)

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
aslushnikovcommented, Feb 1, 2021

Does it happen on Heroku here for everyone? It does look like there might not be enough memory occasionally and firefox fails to open a page.

1reaction
neverbe10commented, Feb 6, 2021

Does it happen on Heroku here for everyone? It does look like there might not be enough memory occasionally and firefox fails to open a page.

I agree I went with digital ocean, and it seems to work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Playwright error (Target closed) after navigation - Stack Overflow
It seems to me that the only problem was with your initial promise composition, I've just refactored the promise to async/await and using ......
Read more >
EventTarget.addEventListener() - Web APIs | MDN
It works on any event target, not just HTML or SVG elements. ... If not specified, defaults to false – except that in...
Read more >
Puppeteer | Puppeteer
Create an automated testing environment using the latest JavaScript and browser features. Capture a timeline trace of your site to help diagnose performance ......
Read more >
Web Performance Recipes With Puppeteer - Addy Osmani
This guide has recipes for automating Web Performance measurement with Puppeteer.
Read more >
Puppeteer documentation - DevDocs
newPage (); await page.goto('https://example.com'); await browser.close(); })(); ... Emitted when a target is created, for example when a new page is opened ...
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