Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] (Browser.newPage): target is undefined #4922

Closed
neverbe10 opened this issue Jan 7, 2021 · 7 comments
Closed

[BUG] (Browser.newPage): target is undefined #4922

neverbe10 opened this issue Jan 7, 2021 · 7 comments
Assignees

Comments

@neverbe10
Copy link

neverbe10 commented Jan 7, 2021

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)
@mxschmitt
Copy link
Member

Hi, might be connected to playwright-community/heroku-playwright-example#8 and the reason here #4740. I was also not yet able to run Firefox with 1.7.0 on Heroku.

@mxschmitt
Copy link
Member

Seems for me it was fixed when using the next-versions (beta). Could you also try that so it can verified and is fixed in the next version. npm install playwright-firefox@next. Thanks!

@neverbe10
Copy link
Author

@mxschmitt I updated the version, but it's still not working. I'm going with another hosting site

@foremtehan
Copy link

same here, I happens randomly on firefox browser:

Something went wrong: Error: browserContext.newPage: Protocol error (Browser.newPage): target is undefined newPage@chrome://juggler/content/TargetRegistry.js:307:5 

@aslushnikov
Copy link
Collaborator

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.

@neverbe10
Copy link
Author

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

@FarhadMohseni
Copy link

I have the same problem on amazon EC2, Version : 1.15.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants