Commit Graph

233 Commits (master)

Author SHA1 Message Date
Ariya Hidayat 26b28d7842 printenv.js: New example to show system.env.
This is very similar to Unix common 'printenv'.

http://code.google.com/p/phantomjs/issues/detail?id=271
2012-03-15 01:33:27 -07:00
Ariya Hidayat b7d7cfc542 Update more examples to use system.args.
http://code.google.com/p/phantomjs/issues/detail?id=276
2012-03-15 01:11:30 -07:00
execjosh b73ec44796 Update examples to use system.args.
Also update coffee-script script path names in usage messages.

http://code.google.com/p/phantomjs/issues/detail?id=276
2012-03-15 01:11:30 -07:00
Ariya Hidayat 6c7b0207f4 Make 'Keep Alive' option to use camel case.
Change 'keep-alive' to 'keepAlive' in the option for the server.
This allows setting the value (in JS object literal) without quoting.

http://code.google.com/p/phantomjs/issues/detail?id=429
2012-03-14 10:52:57 -07:00
Milian Wolff 7b909bfe45 Add example for keep-alive enabled webserver.
See examples/serverkeepalive.js.

http://code.google.com/p/phantomjs/issues/detail?id=416
2012-03-13 19:01:24 -07:00
Ariya Hidayat 74d4a6bd90 Change tweets.js example to official HeadlessPhantom Twitter account.
http://code.google.com/p/phantomjs/issues/detail?id=425
2012-03-12 21:35:40 -07:00
Brian Donovan f34e8b1528 Without arguments, functions must use parentheses in CoffeeScript.
http://code.google.com/p/phantomjs/issues/detail?id=326
2012-03-05 21:34:52 -08:00
Ariya Hidayat 1ae3c5aa2b Change follow.* example to Twitter accounts of PhantomJS contributors.
http://code.google.com/p/phantomjs/issues/detail?id=405
2012-03-04 21:49:47 -08:00
Chris Smith ddc0a7d623 Fix jasmine example terminating too early against jasmine 1.1.0.
The .finished-at element that was being checked for is present all
the time during the test run, so the waitFor call ended too early.

http://code.google.com/p/phantomjs/issues/detail?id=402
2012-03-01 08:17:51 -08:00
Milian Wolff 61eb86782b Filesystem module should allow reading and writing binary files.
CommonJS proposal: http://wiki.commonjs.org/wiki/Filesystem/A.
It's called "raw".

http://code.google.com/p/phantomjs/issues/detail?id=400

Squashed commit of the following:

commit dd5fab4778bb7b67f1eca26a07d430aadd458c6e
Author: Milian Wolff <milian.wolff@kdab.com>
Date:   Thu Feb 23 16:19:21 2012 +0100

    the "mode" string is now properly parsed, and not only the first
    char evaluated. This allows us to do fancy things like

    fs.open(file, "rw+"); // read/write/append

    Furthermore .read() is adapted such that it will always return the
    full file contents, no matter where we have seeked to before (i.e.
    by passing + we seek to the end, hence read() would always return
    an empty string).

    To open a binary file, pass "b" in the mode string to fs.open, e.g.:

    fs.open(file, "rb"); // read binary
    fs.open(file, "wb"); // write binary
    fs.open(file, "rwb+"); // read/write binary, append

    alternatively, one can use these shortcuts:

    fs.write(file, contents, "b"); // write binary
    fs.read(file, "b"); // read binary

    Unit tests are extended and the echoToFile.js example fixed (it did not
    close the file, which lead to the contents never getting written
    on-disk since flush() is never called).

    Also note that the FileSystem::open method was cleaned up and at least
    one memory leak (if QFile* could not open) was fixed. The code should
    now also be more C++-like.

commit 41139951138491459accefab22d48eba7b0b9900
Author: Milian Wolff <milian.wolff@kdab.com>
Date:   Wed Feb 15 16:39:23 2012 +0100

    use QString instead of QByteArray for raw binary data

    QByteArray is simply unusable in JavaScript, since functions like
    e.g. window.btoa expect a string. Also there is no sane way to
    create a byte array in javascript, as ArrayBuffer e.g. is not
    supported by QScript (at least there is no conversion in place).

    If we use QString and some custom read/write code this all works
    as expected though, we can use window.btoa to base64 encode binary
    data and we can create random binary data using String.fromCharCode

    also adds a unit test

commit e45673486ef27daf916902153217f9e5001b68c9
Author: Milian Wolff <milian.wolff@kdab.com>
Date:   Wed Feb 15 14:39:15 2012 +0100

    make it possible to read/write raw/binary files

    this adds File::readRaw and File::writeRaw functions,
    as well as 'shimmed' versions FS::readRaw and FS::writeRaw

    these functions directly use QFile and QByteArray instead of
    QTextStream and QString, making it possible to read and write
    binary data, e.g. images and such.
2012-02-29 07:55:00 -08:00
Ariya Hidayat 4515332d9d Merge remote-tracking branch 'KDAB/printing-margin' 2012-02-23 07:56:45 -08:00
Milian Wolff a638a07339 js-ify, rename and extend print-margins property
Now the left/top/right/bottom print margins can be set separately
using the pageSize.margin property. You can either use

pageSize.margin = "10px"

or use a map to set the margins separately:

pageSize.margin = {
  left: "10px",
  top: "5cm",
  right: "7in",
  bottom: "13mm"
};

pageSize.border is now a synonym for pageSize.margin to keep
compatibility to existing scripts.

ISSUE: 388 (http://code.google.com/p/phantomjs/issues/detail?id=388)
2012-02-23 14:25:16 +01:00
Milian Wolff 1411ebdff6 make POST/PUT data accessible from phantomjs server scripts
For POST and PUT request we now read all data as defined by
the Content-Length header into request.rawData property.
This property is a QByteArray which neatly maps to an array
in javascript.

For POST requests with Content-Type = applicaiton/x-www-form-urlencoded
we furthermore provide a parsed, easy-to-use request.post property.
This one is a QVariantMap of the decoded form data.

There is a new postserver.js example that shows the usage.

The unit test is extended to test the new (and old) features
of the server.

TODO: test that verifies proper decoding of UTF8 data, which
is not yet possible since I see no way to do a post-request
using phantomjs with an explicitly defined charset

ISSUE: 340 (http://code.google.com/p/phantomjs/issues/detail?id=340)
2012-02-15 18:41:51 -08:00
Leo Franchi bbce8920d0 Make Mongoose webserver asynchronous.
This allows for asynchronous reply handling, which is much more logical when dealing with the async
nature of PhantomJS like page.open(). This uses a async patch from Andy Rahn's Mongoose close,
available here: http://code.google.com/r/andyrahn-async/

This is from https://github.com/ariya/phantomjs/pull/202.

http://code.google.com/p/phantomjs/issues/detail?id=326
2012-02-14 23:08:38 -08:00
Ariya Hidayat 5528c046db Some API changes in the WebServer module.
Trying to match http://nodejs.org/docs/latest/api/http.html.

For the server response:

  * Change writeBody to write
  * Change writeHeaders to writeHead

For the request object, 'headers' is now an object containing all
key-value pairs of the actual HTTP headers.

'queryString' is folded into 'url' key.

Non-standard keys in the request: isSSL, remotePort, remoteIP,
remoteUser, are disabled in the mean-time (will be revisited after 1.4
release).

Implementation-wise, the request object is now a simple key-value pair
using QVariant, as opposed to the heavy QObject instance.

http://code.google.com/p/phantomjs/issues/detail?id=115
2011-12-19 18:38:21 -08:00
Ariya Hidayat feafb4f5a3 Add the CoffeeScript version of simpleserver.
This is for the new simpleserver example introduced in commit 9eae7f1.

http://code.google.com/p/phantomjs/issues/detail?id=115
2011-12-19 17:55:27 -08:00
Ariya Hidayat 9eae7f101b Add a simpler example for the WebServer module.
This does nothing but to start an HTTP server on the given port.
The request is merely dumped back as the formatted response.

This example is useful for simple troubleshooting.

http://code.google.com/p/phantomjs/issues/detail?id=115
2011-12-19 08:28:06 -08:00
Ariya Hidayat 6983f6bdf1 Update Sencha folks. 2011-12-19 01:14:31 -08:00
Milian Wolff bd2052631f basic unit testing for WebServer.listen 2011-11-15 13:45:11 +01:00
Milian Wolff a6bde751a9 extend WebServerResponse API 2011-11-15 13:45:11 +01:00
Milian Wolff 705eda8823 add read-properties to WebServerRequest 2011-11-15 13:45:11 +01:00
Milian Wolff 245eec551f make it possible to access the request headers 2011-11-15 13:45:11 +01:00
Milian Wolff f30bfa9fb7 extend WebServerRequest API 2011-11-15 13:45:11 +01:00
Milian Wolff 0abdc7f9ed very basic response + request handling for WebServer
the api is very limited but already makes the server.js example
do something useful with the server
2011-11-15 13:45:11 +01:00
Milian Wolff 73705e484b first work towards a WebServer
this is the minimal server that gets properly embedded into
the phantomjs space but the .listen api is missing actually
useful options (incoming request and ability to write to client)
2011-11-15 13:44:47 +01:00
Ariya Hidayat 8ffd7a2403 detectsniff example: Check if the web page sniffs the user agent.
http://code.google.com/p/phantomjs/issues/detail?id=263
2011-10-25 11:33:10 -05:00
Nick Rowe 56f470e3a1 Change comment in run-jasmine example to be consistent with the way the code is written 2011-10-06 13:43:12 -07:00
Ariya Hidayat 8b0f13309a examples/follow: Update Sencha folks. 2011-09-20 21:55:24 -07:00
Gregor Martynus cec8b5672e Just a simple change to not only log the failed error, but also the actual message 2011-09-21 02:50:21 +03:00
Ariya Hidayat 1178637805 Remove unported examples that do not work anymore. 2011-09-16 17:49:09 -07:00
Ariya Hidayat e07307ec1d Merge pull request #155 from Roejames12/master
A ton of updates
2011-09-14 21:45:08 -07:00
IceArmy 5b24d2417a Fix injectme.coffee example which was injecting 'injectme.js' instead of itself 2011-09-13 14:50:12 -07:00
IceArmy c119a4788e Merge branch 'master' of git://github.com/ariya/phantomjs 2011-09-13 13:16:20 -07:00
Ivan De Marino e0e5535e0e Updated examples to use "require('webpage').create()" instead of "new WebPage()". 2011-09-12 21:17:54 +01:00
Ariya Hidayat bcd01d222b netlog.coffee: Fix wrong address to be loaded.
http://code.google.com/p/phantomjs/issues/detail?id=227
2011-09-10 11:05:25 -07:00
Ariya Hidayat 1fd9c20835 netlog: Example to dump live network traffic.
http://code.google.com/p/phantomjs/issues/detail?id=227
2011-09-10 09:15:34 -07:00
IceArmy e9d87f0fb2 Merge branch 'master' of git://github.com/ariya/phantomjs 2011-09-08 15:14:34 -07:00
Ariya Hidayat 6a79ea7e6d Implement require('fs').
This is mostly based on Ivan's work, see
https://github.com/ariya/phantomjs/pull/153

http://code.google.com/p/phantomjs/issues/detail?id=47
2011-09-08 10:00:07 -07:00
IceArmy f51b5144f0 Fix issue 225: netsniff.coffee produces invalid HAR 2011-09-08 00:25:51 -07:00
Ariya Hidayat e45c5328b9 CoffeeScript version of unrandomize example. 2011-09-07 17:52:58 -07:00
Julien Ammous 217b7ecbd4 typo 2011-08-29 00:12:48 +03:00
execjosh b5bb07faa4 Add examples for phantom.outputEncoding 2011-08-25 03:15:26 +09:00
Ariya Hidayat 051f3ea839 examples/pizza: Switch to use Yelp.
http://code.google.com/p/phantomjs/issues/detail?id=200
2011-08-23 23:34:50 -07:00
Ariya Hidayat 8af4fa714c examples/follow: Update Sencha dudes. 2011-08-21 00:16:37 -07:00
Ariya Hidayat 319fd80ec3 Add callback for page initialization.
http://code.google.com/p/phantomjs/issues/detail?id=143
2011-08-20 17:57:01 -07:00
Ivan De Marino 3046bd994e Spotted a mistake in "scandir.[js|coffee]": was still using "phantom.fs" API. 2011-08-04 22:00:18 +01:00
Alexey Palazhchenko ab138bc42c QUnit runner: exit with 1 if network is unreachable. 2011-07-06 14:30:58 +04:00
Ariya Hidayat 1354d65acf Merge pull request #100 from sujal/master
Simple comment correction in injectme.* example
2011-06-28 18:05:50 -07:00
sujal 59843bfcdf cleanup injectme.* example comment
the comment confused me at first, making me think there was a "better"
or alternate way to do this, so I spent 45 minutes searching the docs
for a mention of loadJsFile.

Hopefully this saves someone else a few minutes.
2011-06-28 19:34:01 -04:00
Ivan De Marino 3807b9dc4d Now, if "fs.open" fails, it throws an exception.
* This is implemented with a javascript-shim
2011-06-28 21:35:27 +01:00
Ivan De Marino a0e1888c2c Moved the "fs" object to be in the global/window space: will not be attached to the "phantom" object anymore.
* Once (and if) we implement support for CommonJS Module Loading, a "require("fs")" will be required.
2011-06-28 21:02:48 +01:00
Ivan De Marino 6b04ee23c1 Introducing File I/O API in PhantomJS.
* This is the  squash of 30 commits, so it's meaty
* Inspired by HammerJS (see https://github.com/senchalabs/hammerjs)
* Not yet 100% complete
* Final aim is to provide a CommonJS/Filesystem compliant API (see http://wiki.commonjs.org/wiki/Filesystem)
2011-06-27 23:14:05 +01:00
Ariya Hidayat da629874d3 examples/feature.js: Show supported/unsupported features.
Feature detection is done via Modernizr.
2011-06-26 14:05:48 -07:00
Dunk Fordyce 42472aa92f fix page/phantom variable wrongness 2011-06-21 14:34:41 +01:00
Ariya Hidayat 9931279ccc Remove unnecessary console redirection. 2011-06-19 15:28:58 -07:00
rgieseke e09da4e1d8 netsniff.coffee: Remove dot in prototype check. 2011-06-17 09:05:19 +02:00
rgieseke 7e4a5fd33e injectme.coffee: Add CoffeeScript version. 2011-06-17 09:04:08 +02:00
rgieseke 913b214d91 useragent.coffe: Change useragent as in js version. 2011-06-17 08:45:41 +02:00
rgieseke e5064db060 pizza.coffee: Add missing onConsoleMessage. 2011-06-17 08:25:35 +02:00
rgieseke 2c8e9bd5b4 Examples: new coffeescript versions. 2011-06-16 22:56:06 +02:00
Ivan De Marino e2ee86e0ac Minor cleanup on 'sleepsort.js' 2011-06-16 14:48:41 +01:00
Ivan De Marino d00ed3f2fc sleepsort.js - This must go in for 1.2 :P
* It's so silly, it has to.
* Also, it shows how "powerful" the function scoping is
2011-06-16 11:46:10 +01:00
Ariya Hidayat 6b28a956ac Refer to function argument 'startTime', not from page. 2011-06-13 08:11:40 -07:00
Ivan De Marino 22ee075cc2 Removing "page.click()" for now.
There is need for a discussion to decide how to do this.
2011-06-10 17:08:46 +01:00
Ivan De Marino 75403737c4 Added "includeJs()" to "page".
* It includes a script in the page
* It uses a callback to ensure any code dependent on the include runs afterwards
* It uses the signal "javaScriptAlertSent" to do the trick (is there another way to be notified of the "onLoad" event from outside the page context?)
* It uses a "private" slot "_appendScriptElement" to pass the script url in the page context (is there a better way?)
2011-06-10 17:08:46 +01:00
Ivan De Marino a0f8f2491d "loadJsFile()" -> "injectJs"
* According to Issue #32 (http://code.google.com/p/phantomjs/issues/detail?id=32) I added a "lookup logic" that searchs for the file following those steps:
*# Search for file at given path (relative to PWD or absolute - no difference)
*# Is file there? Inject it
*# Is file not there? Try looking for it in "scriptLookupDir"
*# Is file there? Inject it
*# Is file not there? abort
* "scriptLookupDir" is an extra property for WebPage, that, as by it's name, defines a place where to look to script to inject
* Script can alter the scriptLookupDir, if they want
* Updated "injectme.js" accordingly
2011-06-10 17:08:45 +01:00
Ivan De Marino bb0b820f72 Merge remote-tracking branch 'upstream/master' into utilities 2011-06-09 11:50:54 +01:00
IceArmy 0bfd28e67d example/netsniff.coffee: Format the output to HAR 1.2 specification. 2011-06-09 00:58:03 -07:00
Ariya Hidayat c2c6cbc287 example/netsniff.js: Format the output to HAR 1.2 specification. 2011-06-08 23:47:14 -07:00
Ariya Hidayat 751e471068 Better timing for onResourceRequested and onResourceReceived.
We record the time right inside the network access manager. This gives
better accuracy than doing it from JavaScript side, no loss due to the
latency of signal slot connection.
2011-06-08 23:32:14 -07:00
Ariya Hidayat 1cae77a3e0 Add 'onResourceReceived' event, fired when resource is being received.
This is now being used in the netsniff.js example.
2011-06-08 01:10:00 -07:00
Ivan De Marino 5b6f2731c4 Added support for "page.click()" and "page.loadJsFile()".
* click() accepts a "querySelectorAll" input - can click on multiple things in one call
* loadJsFile() is synchronous at loading JS in the page
* added 2 examples in JavaScript to show how to use (and test) the new methods
* NOTE: someone will have to generate the .coffee version - I tried using "http://ricostacruz.com/js2coffee/" but it hangs and I'm not willing to learn why :P - I don't like Coffee Script.
2011-06-07 17:20:22 +01:00
IceArmy 805c824ff3 Convert netsniff.js to CoffeeScript 2011-06-07 02:52:01 -07:00
Ariya Hidayat 8722399c0a Add "onResourceRequested" event, fired when request is started.
To see how this is being used, see the new examples/netsniff.js.

http://code.google.com/p/phantomjs/issues/detail?id=2
2011-06-07 00:06:08 -07:00
Ariya Hidayat cf8a890f8b loadspeed.js: Fixed missing semicolons. 2011-06-06 23:52:39 -07:00
IceArmy 88f9434a0c Convert run-jasmine.js to CoffeeScript 2011-06-06 19:01:45 -07:00
IceArmy 331be469bc Convert run-qunit.js to CoffeeScript 2011-06-06 18:57:46 -07:00
IceArmy 6390f92550 Convert imagebin.js to CoffeeScript 2011-06-06 18:52:33 -07:00
Ariya Hidayat 3170b2b4b6 imagebin.js: Example of file upload inside form.
Warning: this script has zero error checking.
2011-06-05 01:11:59 -07:00
IceArmy 253469b03e Improve waitfor.coffee readability 2011-06-02 17:18:25 -07:00
IceArmy 5e876a6517 Improve weather.coffee a little 2011-06-02 17:18:11 -07:00
IceArmy ac354d7804 Convert render_multi_url.js to CoffeeScript 2011-06-02 00:46:50 -07:00
IceArmy bdf4fb4571 Convert post.js to CoffeeScript 2011-06-02 00:46:50 -07:00
IceArmy 6b2c492796 Port tweets.coffee to PhantomJS 1.2 2011-06-02 00:46:50 -07:00
IceArmy 39d8522c3a Port weather.coffee to PhantomJS 1.2 2011-06-02 00:46:50 -07:00
IceArmy dd0d437b89 Port countdown.coffee to PhantomJS 1.2 2011-06-01 23:20:47 -07:00
IceArmy 80131a2353 Port waitfor.coffee to PhantomJS 1.2 2011-06-01 19:51:17 -07:00
Ivan De Marino e59054247c Converted 'cycle_multiple_urls.js' to PhantomJS 1.2 (and renamed to 'render_multi_url.js').
Given that I practically rewrote it, I took the liberty to rename it based on my personal taste ;)
2011-06-01 18:37:57 +01:00
Ivan De Marino 93d2c30248 Converted 'run-jasmine.js' to PhantomJS 1.2 2011-06-01 17:30:27 +01:00
Ivan De Marino afce9b83b0 Converted 'run-qunit.js' to PhantomJS 1.2 AND fixed a stupid mistake in 'waitFor' 2011-06-01 17:24:32 +01:00
Ivan De Marino f8e59f92f8 Ported 'waitfor.js' to Phantom 1.2.
* There is a problem though: the script causes a "segfault" on phantom.exit() - I didn't investigated why yet
2011-06-01 16:29:44 +01:00
Ivan De Marino 78cab6b4b1 Converted "weather.js" for PhantomJS 1.2 2011-06-01 14:55:35 +01:00
Ivan De Marino 811c56b6f3 Ported 'countdown.js' to PhantomJS 1.2 2011-06-01 14:25:22 +01:00
Ivan De Marino b91f5b9632 Converted "tweets.js" to PhantomJS 1.2.
First impression: PhantomJS 1.2 makes a lot of sense.
But there are issues if we try to pass a DOM node as a return value for calls to "evaluate"
2011-06-01 14:18:08 +01:00
Ariya Hidayat a7a8a6749a Merge pull request #49 from rgieseke/cs-examples
Port CoffeeScript examples to use WebPage object.
2011-05-29 12:33:03 -07:00
rgieseke 2a8fac45b4 Indent with 2 spaces. 2011-05-29 14:21:25 +02:00
rgieseke 5b8a40e763 Remove unused variable. 2011-05-29 14:01:55 +02:00
Ariya Hidayat 5be29972cf WebPage callback for its console message.
See http://code.google.com/p/phantomjs/issues/detail?id=12.

By default, WebPage is "silent" and does not report its console message.
This can be overridden easily, e.g:

  var page = new WebPage();
  page.onConsoleMessage = function (msg) {
    console.log(msg);
  };
  page.open(.....);
2011-05-28 21:16:18 -07:00
Ariya Hidayat b1af26ecc0 Support different HTTP operations for loading a page.
http://code.google.com/p/phantomjs/issues/detail?id=88
2011-05-28 02:06:20 -07:00
Ariya Hidayat 7e099abaf2 User-agent is part of WebPage settings, not WebPage object itself. 2011-05-27 22:50:33 -07:00