Last active
May 30, 2019 16:50
-
-
Save hnestmann/8dfe33f15ae2a8574c805ee98d6cdd86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** source https://github.com/GoogleChromeLabs/puppeteer-examples/blob/master/side-by-side-pageload.js | |
| * Thanks Google | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| **/ | |
| const puppeteer = require('puppeteer'); | |
| const DEFAULT_VIEWPORT = {width: 1000, height: 800, deviceScaleFactor: 2}; | |
| const hosts = ['https://bbsv-011.sandbox.us01.dx.commercecloud.salesforce.com','https://bbsv-021.sandbox.us01.dx.commercecloud.salesforce.com'] | |
| const pages = [ | |
| '/on/demandware.store/Sites-RefArch-Site/en_US/ConsentTracking-SetSession?consent=true', | |
| '/on/demandware.store/Sites-RefArch-Site/en_US/Login-Show', | |
| '/s/RefArch/mens/?lang=en_US', | |
| '/s/RefArch/mens/clothing/?lang=en_US', | |
| '/s/RefArch/mens/clothing/suits/?lang=en_US', | |
| '/s/RefArch/navy-single-pleat-wool-suit/25686514M.html?lang=en_US', | |
| '/s/RefArch/womens/?lang=en_US', | |
| '/s/RefArch/womens/jewelry/?lang=en_US', | |
| '/s/RefArch/womens/jewelry/?lang=en_US&pmin=0%2e00&pmax=20%2e00&lang=en_US', | |
| '/s/RefArch/womens/jewelry/?lang=en_US', | |
| '/s/RefArch/worn-gold-curved-earring/25720016M.html?lang=en_US' | |
| ] | |
| var screen0pages = pages.map(element => hosts[0] + element); | |
| var screen1pages = pages.map(element => hosts[1] + element); | |
| async function launch(browser, urls) { | |
| const pages = await browser.pages() | |
| const page = pages.pop(); | |
| await page.setViewport(DEFAULT_VIEWPORT); | |
| const client = await page.target().createCDPSession(); | |
| // Emulate "Slow 3G" according to WebPageTest. | |
| await client.send('Network.emulateNetworkConditions', { | |
| offline: false, | |
| latency: 400, | |
| downloadThroughput: Math.floor(400 * 1024 / 8), // 400 Kbps | |
| uploadThroughput: Math.floor(400 * 1024 / 8) // 400 Kbps | |
| }); | |
| await client.send('Emulation.setCPUThrottlingRate', { rate: 4 }); | |
| var startTime = Date.now(); | |
| var url; | |
| for (var i = 0; i < urls.length; i++) { | |
| url = urls[i]; | |
| await page.goto(url, { waitUntil: 'networkidle2' }) | |
| }; | |
| console.info('Finished url ' + url +' after ' + (Date.now() - startTime).toString()) | |
| return page; | |
| } | |
| (async () => { | |
| const browser = await puppeteer.launch(); | |
| const page = await browser.newPage(); | |
| // measure screen | |
| const screen = await page.evaluate(() => { | |
| return { width: window.screen.availWidth, height: window.screen.availHeight }; | |
| }); | |
| await browser.close(); | |
| // Take up full desktop space | |
| DEFAULT_VIEWPORT.width = Math.floor(screen.width / 2); | |
| DEFAULT_VIEWPORT.height = screen.height; | |
| const totalSpacerWidthAddition = 0; | |
| const totalWidthOfWindows = 2 * DEFAULT_VIEWPORT.width; | |
| const totalWidthOfWindowsWithSpacers = totalWidthOfWindows + totalSpacerWidthAddition; | |
| const centerScreenX = screen.width / 2; | |
| const centerScreenY = screen.height / 2; | |
| let dx0 = 0; | |
| let dx1 = DEFAULT_VIEWPORT.width; | |
| const x1 = Math.floor(centerScreenX - (totalWidthOfWindowsWithSpacers / 2) + dx1); | |
| const y = Math.floor(centerScreenY - (DEFAULT_VIEWPORT.height / 2)); | |
| const browser0 = await puppeteer.launch({ | |
| headless: false, | |
| executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', | |
| args: [ | |
| `--window-size=${DEFAULT_VIEWPORT.width},${DEFAULT_VIEWPORT.height}`, `--window-position=${dx0},0` | |
| ] | |
| }); | |
| const browser1 = await puppeteer.launch({ | |
| headless: false, | |
| executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', | |
| args: [ | |
| `--window-size=${DEFAULT_VIEWPORT.width},${DEFAULT_VIEWPORT.height}`, `--window-position=${dx1},0` | |
| ] | |
| }); | |
| launch(browser0, screen0pages); | |
| await launch(browser1, screen1pages); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment