Skip to content

Instantly share code, notes, and snippets.

@nickl-
Last active December 11, 2015 08:48
Show Gist options
  • Select an option

  • Save nickl-/4575427 to your computer and use it in GitHub Desktop.

Select an option

Save nickl-/4575427 to your computer and use it in GitHub Desktop.
Respect/Foundation new `make phantomjs-inject` to inject javascript into any page right from the shell with `alert()`, `console.log()` and/or `return` values echoed to stdout. Now with verbose target `make phantomjs-inject-verbose` for complete transparency, for those times when you just have to know more about what exactly is going on. Find out…
$ make phantomjs-inject
Respect/Foundation: 0.1.13
Usage: make phantomjs-snapshot url=<site-url> [code=jQuery Script] or use stdin
Example:
As command line argument:
make phantomjs-inject url=respect.li code='alert($$("title").text());'
note: requires dollar escaped as double dollar $$
From stdin:
echo 'console.log($("title").text());' | make phantomjs-inject url=respect.li
note: stdin allows for raw input so $ doesn't get processed
Tips:
Use single quotes to avoid shell interpretation.
Both alert and/or console.log will echo to stdout.
Use target phantom-inject-verbose for detailed output while debugging.
$ make phantomjs-inject url=respect.li code='
alert($$("title").text());
return $$("h3").first().text();
'
Respect/Foundation: 0.1.13
Respect Project
Simple independent components for building or improving PHP applications.
$ make phantomjs-inject-verbose url=respect.li code='
alert($$("title").text());
return $$("h3").first().text();
'
Respect/Foundation: 0.1.13
Retrieve:
Fetching target page from url:
http://respect.li
Target page opened with status: success
Configure:
Include jQuery library from location:
http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
Inject:
The following function will be injected into the page.
function () {
alert($("title").text());
return $("h3").first().text();
}
Output:
The result from any in script calls to alert() or console.log().
Respect Project
Return:
If anything was returned by the injected function.
Simple independent components for building or improving PHP applications.
Elapse: 7.627s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment