[BUG] (Browser.newPage): target is undefined
See original GitHub issueContext:
- Playwright Version: 1.7.1
- Node.js version: v12.18.3
- Browser: Firefox
- Extra: Heroku Free tier with heroku-playwright-buildpack
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:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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