Skip to content

Instantly share code, notes, and snippets.

@orleika
Last active July 27, 2016 05:45
Show Gist options
  • Save orleika/49ac310531d1e2ce77dcfdf3ccb562e3 to your computer and use it in GitHub Desktop.
Save orleika/49ac310531d1e2ce77dcfdf3ccb562e3 to your computer and use it in GitHub Desktop.
Running Browser environment on Node.js
## Requirements
Python
`$ npm install -g phantomjs`
`$ npm install -g casperjs`
## Run
`$ casperjs index.js`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test page</title>
</head>
<body>
<script src="main.js"></script>
</body>
</html>
var casper = require('casper').create();
casper.start('./index.html');
casper.then(function() {
this.echo(this.getHTML());
});
casper.run();
(function() {
/**
* Do somethings
*/
var script = document.createElement('script');
script.src = 'another.js';
document.getElementsByTagName('head')[0].appendChild(script);
}());
{
"name": "browser-access",
"main": "index.js",
"dependencies": {
"casperjs": "^1.1.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment