-
Notifications
You must be signed in to change notification settings - Fork 302
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
add example for pooling browsers #14
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
CLAs look good, thanks! |
I signed it. |
This fixes #14 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be interesting to have a flag that controls using a pool and not using a pool. And then throw in some console.time
to show the difference in perf.
puppeteer-browser-pool.js
Outdated
const genericPool = require('generic-pool'); | ||
const puppeteer = require('puppeteer'); | ||
|
||
const VIEWPORT = { width: 1028, height: 800, deviceScaleFactor: 2 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, we need linting.
- Can you remove the surrounding whitespaces after
{
and the first key name and the space before}
. - Use 2-space indentation everywhere.
puppeteer-browser-pool.js
Outdated
|
||
const factory = { | ||
create: async () => { | ||
const browser = await puppeteer.launch(puppeteerArgs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does puppeteerArgs
come from?
puppeteer-browser-pool.js
Outdated
const HACKER_NEWS_QUERY_SPA_URL = 'https://hn.algolia.com/?query=angular'; | ||
|
||
|
||
const factory = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
puppeteer-browser-pool.js
Outdated
|
||
const VIEWPORT = { width: 1028, height: 800, deviceScaleFactor: 2 }; | ||
const HACKER_NEWS_SPA_URL = 'https://hn.algolia.com/'; | ||
const HACKER_NEWS_QUERY_SPA_URL = 'https://hn.algolia.com/?query=angular'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use https://hn.algolia.com/?query=chrome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also build off the base url.
puppeteer-browser-pool.js
Outdated
return page; | ||
}, | ||
destroy: (browser) => { | ||
browser.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return browser.close();
puppeteer-browser-pool.js
Outdated
// this request will use the instance from the current browser pool resulting in faster response | ||
const responseHackerNewsWithQuery = await getContent(HACKER_NEWS_QUERY_SPA_URL); | ||
console.log(responseHackerNewsWithQuery); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline
Is it possible to add a few more examples to the demo that helps show why a pool is necessary in some cases. Otherwise it's easy just to use the same browser instance to open 2 tabs for the URLs you're using. |
The reason we are parallelizing work through browsers and not pages is because one page crash might bring down the whole browser and also each page isn't guaranteed to be totally clean (cookies and storage might bleed-through as seen here). |
But that is unlikely :) The other one is a big in chrome that hopefully
gets fixed soon.
I'd prefer to encourage folks to use separate browser instances only when
it makes sense. It comes with much more overhead than launching a single
instance. Having a demo that shows when/why you'd need to go with many
instances would be more helpful IMO.
…On Thu, Aug 23, 2018, 10:40 PM Rahul Kumar ***@***.***> wrote:
The reason we are parallelizing work through browsers and not pages is
because one page crash might bring down the whole browser and also each
page isn't guaranteed to be totally clean (cookies and storage might
bleed-through as seen here
<https://bugs.chromium.org/p/chromium/issues/detail?id=754576>).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOigNgNRi0CBOgBxvKXxhW1e54Lpzaoks5uT5HQgaJpZM4WD4pV>
.
|
i have used single browser in production and it was not stable over long periods of time maybe because i was using --single process flag. |
I'm not arguing the benefits for certain use cases. I'm saying we should
have a demo that shows a case where you would want to do pooling.
On Mon, Aug 27, 2018, 2:36 AM Rahul Kumar ***@***.***> wrote:
i have used single browser in production and it was not stable over long
periods of time maybe because i was using --single process flag.
Even browserless.io
<https://docs.browserless.io/blog/2018/06/04/puppeteer-best-practices.html>
recommends running multiple browsers opposed to running multiple pages
I'm confused because this is an argument against keeping a pool of long
running browsers open....
… —
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOigJeh0Q54JCtldEvyBbZbs6FyvoDpks5uU72xgaJpZM4WD4pV>
.
|
Ok i will add it |
return page; | ||
}, | ||
destroy: (browser) => { | ||
return browser.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You receive page from (create), in destroy you receive bro page, so page will be closed not browser
this is an example for pooling browsers resulting in faster load times of pages since we not don't have to open new browser for each request .
This results in improve load times especially in case of SPAs since cached resources can be reused.