Created
September 13, 2017 03:57
-
-
Save kawasako/ae7a44b2571f5785c31204c2974213f1 to your computer and use it in GitHub Desktop.
nightmare cwa capture
This file contains 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
const Nightmare = require('nightmare'); | |
const path = require('path'); | |
const USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'; | |
const VIEWPORT_WIDTH = 375; | |
const VIEWPORT_HEIGHT = 3000; | |
function run() { | |
let nightmare = Nightmare({ | |
show: true, | |
openDevTools: { | |
mode: 'detach' | |
}, | |
webPreferences: { | |
preload: path.resolve('modules/simulator/LCSMockLite.js') | |
} | |
}); | |
return nightmare | |
.useragent(USER_AGENT) | |
.viewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT) | |
.goto('https://ch-news.line-apps-beta.com/channel/') | |
.evaluate(function() { | |
return { | |
height: document.body.scrollHeight, | |
width: document.body.scrollWidth | |
} | |
}) | |
.screenshot('public/ss/' + Date.now() + '.png') | |
.end() | |
.then(function (result) { | |
console.log(result); | |
}) | |
.catch(function (error) { | |
console.error('Search failed:', error); | |
}); | |
} | |
module.exports = { run }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment