Comments (4)
@thomasdondorf thank you clearing up my misunderstanding. Apologies if it's a basic question, but I'm still not sure how one would go about returning pageTitle
. Plain old, calling of pageTitle as a variable outside of the function didn't work.
from puppeteer-cluster.
This is a misunderstanding regarding the Promise of the cluster.queue
function. The Promise of the queue function resolves as soon as the job is queued, not when the job is finished.
This will change in Version 1. queue
will not return a Promise anymore and there will be another function called execute
which queues the data and waits until the job is finished.
For more discussion see #10
from puppeteer-cluster.
All good :)
Right now you cannot return data from within the function, but instead you can collect it via an array in the outer scope like this:
const pageTitles = [];
const extractTitle = async ({ page, data: url }) => {
await page.goto(url);
const pageTitle = await page.evaluate(() => document.title);
pageTitles.push(pageTitle);
};
// queue your pages
await cluster.idle(); // wait for the jobs to be finished
// pageTitles should now be filled with your page titles
Alternatively you could also use callbacks to collect your data (or create promises and use their resolve as callback).
Does that clear things up?
from puppeteer-cluster.
@thomasdondorf yes this certainly helps to clear things up! Thank you for helping me out with this!
from puppeteer-cluster.
Related Issues (20)
- Try to running on windows 10 and nodejs 18 error : Error: Unable to launch browser, error message: Failed to launch the browser process! [0110/004354.813:ERROR:icu_util.cc(243)] Invalid file descriptor to ICU data received. HOT 2
- Single setup before starting concurrent cluster? HOT 2
- I think a timeout of `0` should disable timeouts HOT 2
- Clear up Concurrency wording incorrect usage HOT 5
- Feature: Lifetimes
- How To Stop Worker To Become Idle automatically
- Expose stats via prometheus HOT 2
- Screen shot getting stuck forever
- Use same URL but diffetent logic on each browser HOT 1
- Concurrency launch: CONCURRENCY_BROWSER definition slightly misleading HOT 2
- Error detection super slow with new Puppeteer versions HOT 1
- Support to new puppetter versions HOT 1
- share the dockerfile I'm using
- Suggestion: Allow pool of already instantiated browser workers
- how to open the progress view and monitoring statistics? HOT 1
- cluster concurrent seems not work HOT 1
- Regarding resource usage HOT 1
- Worker Error getting browser page HOT 1
- How to set args like .launch({ args: [] }) ? HOT 3
- Has anyone managed to use separate data for each browser?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from puppeteer-cluster.