Puppeteer is working slower than PhantomJS
See original GitHub issueI have tested puppeteer vs phantomjs using http://google.com as url . Puppeteer is too slow compared to phantomjs. puppeteer = 8004 ms phantomjs = 7 ms
Code for phantomjs: phantom.js
var path = require('path')
var childProcess = require('child_process')
var phantomjs = require('phantomjs')
var binPath = phantomjs.path;
var address = process.argv[2];
var childArgs = [
path.join(__dirname, 'phantomjs-script.js'),
address
];
var child = childProcess.execFile(binPath, childArgs, {timeout:60000}, function(err, stdout, stderr) {
console.log(stdout);
})
phantomjs-script.js
var start = new Date().getTime(), end;
console.log('start: ',start);
var page = require('webpage').create(),
system = require('system'),
address, screenWidth, screenHeight;
try {
address = system.args[1];
screenWidth = 1000;
screenHeight = 700;
page.viewportSize = {width: screenWidth, height: screenHeight};
page.settings.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/52.0.2743.116 Chrome/52.0.2743.116 Safari/537.36";
page.open(address, function (status) {
console.log('')
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
page.render("phantom.png");
phantom.exit();
}
});
} catch(e){
phantom.exit()
}
end = new Date().getTime();
console.log('end: ', end);
console.log((end-start)/1000);
Code for puppeteer puppeteer.js
var path = require('path');
var childProcess = require('child_process');
var address = process.argv[2];
var childArgs = [
path.join(__dirname, 'puppeteer-script.js'),
address,
foldername
];
var child = childProcess.execFile('node', childArgs, {} , function(err, stdout, stderr) {
console.log(stdout);
});
puppeteer-script.js
var start = new Date().getTime(), end;
console.log('start: ',start);
const puppeteer = require('puppeteer');
var address, foldername, screenWidth, screenHeight;
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
try {
address = process.argv[2];
screenWidth = 1000;
screenHeight = 700;
await page.setViewport({width:screenWidth, height: screenHeight});
await page.goto(address).then(async (msg) => {
console.log('--------------------------------------------');
if (msg.ok !== true) {
console.log('Unable to load the address!');
await browser.close();
} else {
await page.screenshot({path: 'puppeteer.png'});
await browser.close();
}
});
} catch(e){
console.log('INSIDE CATCH EXCEPTION!');
await browser.close();
}
end = new Date().getTime();
console.log('end: ', end);
console.log((end-start)/1000);
})();
I need to speed up puppeteer.
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (8 by maintainers)
Top Results From Across the Web
Puppeteer is working slower than PhantomJS #1444 - GitHub
I have tested puppeteer vs phantomjs using http://google.com as url . Puppeteer is too slow compared to phantomjs. ... var start = new...
Read more >PhantomJS vs Puppeteer | What are the differences?
PhantomJS and Puppeteer are both open source tools. Puppeteer with 51.1K GitHub stars and 4.71K forks on GitHub appears to be more popular...
Read more >Building on Puppeteer: Finding a Way Beyond PhantomJS
Most scans also succeed in under 2 seconds compared to the 8 seconds from PhantomJS. The downside is that Puppeteer is a lot...
Read more >How to improve puppeteer startup performance during tests
I've started to debug Puppeteer and these are my findings: Puppeteer is unsurprisingly using child_process.spawn() to spawn a new browser ...
Read more >PhantomJS vs Puppeteer detailed comparison as of 2022 - Slant
When comparing PhantomJS vs Puppeteer, the Slant community recommends PhantomJS for most people. In the question“What are the best headless browsers for ...
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
Guys, @abdurashidv , there is something huge you seem to have missed here :
The asynchronous nature of Javascript, and the sames applies for PhantomJS.
Exactly as what @Everettss said, the end time measure should be done within the page.open callback. Let’s remember PhantomJS main issue: the JS callback hell, and that’s why CasperJS came to the rescue…
Even if the “end = new Date().getTime();” line is written at the end of the file, it will be executed right after the “console.log('start: ',start);” line, because of the way the Javascript’s Call Stack + Event loop works. Thereby resulting in only 7ms.
A nice explained article:
@Everettss I have implemented phantom timing page.open( … ) and it is showing exact time. Phantom and puppeteer are same but in some occasions puppeteer is better than phantomjs.