Created
June 21, 2018 00:24
-
-
Save Spongman/aebb0360e8e707e5187f8c866c6aae67 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<canvas id="canvas" width="1080" height="1080"></canvas> | |
<script type="text/javascript"> | |
var canvas = document.getElementById('canvas'); | |
var gl = canvas.getContext('webgl'); | |
gl.viewportWidth = canvas.width; | |
gl.viewportHeight = canvas.height; | |
gl.clearColor(0.99, 1, 0, 1); | |
gl.clear(gl.COLOR_BUFFER_BIT); | |
</script> | |
</body> | |
</html> |
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 fs = require('fs'); | |
const express = require('express'); | |
const app = express(); | |
const chromeLauncher = require('chrome-launcher'); | |
const CDP = require('chrome-remote-interface'); | |
app.use(express.static(__dirname)); | |
const server = app.listen(8080, function () { | |
console.log('Listening on port %d', server.address().port); | |
}); | |
(async function () { | |
console.log('Launching Chrome...'); | |
let instance = await chromeLauncher.launch({ | |
chromeFlags: [ | |
'--disable-background-timer-throttling', | |
'--disable-default-apps', | |
'--disable-device-discovery-notifications', | |
//'--disable-gpu', | |
'--disable-popup-blocking', | |
'--disable-renderer-backgrounding', | |
'--disable-translate', | |
'--headless', | |
'--no-default-browser-check', | |
'--no-first-run' | |
], | |
port: 9222, | |
loadTimeout: 1000, | |
logLevel: 'verbose', | |
ignoreExceptions: false, | |
ignoreConsole: false, | |
ignoreResourceErrors: false, | |
}); | |
CDP(async (client) => { | |
const { Network, Page } = client; | |
await Network.enable(); | |
await Page.enable(); | |
await Page.navigate({ url: 'http://localhost:8080' }); | |
console.log('Saving snapshot...'); | |
const { data } = await Page.captureScreenshot(); | |
fs.writeFileSync('snapshot.png', Buffer.from(data, 'base64')); | |
await client.close(); | |
await instance.kill(); | |
server.close(function () { | |
console.log('Done'); | |
process.exit(); | |
}); | |
}).on('error', (err) => { | |
// cannot connect to the remote endpoint | |
console.error(err); | |
}) | |
})(); |
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
{ | |
"name": "headless-webgl", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"devDependencies": { | |
"chrome-launcher": "^0.10.2", | |
"chrome-remote-interface": "^0.25.6", | |
"express": "^4.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment