A headless Internet Explorer browser using the .NET WebBrowser Class with a Javascript API running on the V8 engine.

The API is coded as a port of PhantomJS. Perfect for test automation. If you have used phantom before then you already know how to use TrifleJS.

It supports different version of IE interchangeably depending on the current version installed (IE9 can emulate IE7, IE8 or IE9 but not IE10).

C:> TrifleJS.exe --emulate=IE8 --render=http://whatbrowser.org/

IE 8

API Status (79%)

This is the overall status of the API implementation: 145 components in 184 total (ie 79%)

Feature Status Notes
Command Line Options Partial 7 out of 19 options
Global Methods Ready .require() for CommonJS module definition
Object: phantom Partial 9 out of 11 members
Module: System Ready 5 out of 5 members
Module: FileSystem Ready 35 out of 35 members
Module: WebPage Partial 47 out of 71 members
Module: WebServer Ready 19 out of 19 members
Module: ChildProcess Ready 14 out of 14 members
New Features Partial 8 out of 9 options (IE emulation etc)

Latest Updates

For latest updates from the developer follow @triflejs.

Download Beta

This is still very much work-in-progress. Click here for binaries.

Command Line Options

TrifleJS runs on the command line, usually by pointing it to a script.js file.

C:\> TrifleJS.exe examples\version.js --emulate=IE9
phantomjs -> 1.7.0
triflejs -> 0.5.0
internet explorer -> IE9
user agent -> Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/7.0)

Original PhantomJS API Documentation for this section is in:

https://github.com/ariya/phantomjs/wiki/API-Reference#command-line-options

Feature Status Notes
(no arguments) Ready Runs interactive mode (REPL). See below.
path-to/script.js Ready Executes script.js file.
--help or -h Ready Lists command line options and quits.
--version or -v Ready Current Version of TrifleJS
--cookies-file=/path/to/cookies.txt To Do File name to store persistent Cookies.
--disk-cache=[true|false] Unsupported Always true. To clear use --clear-cache.
--ignore-ssl-errors=[true/false] Ready Ignores SSL errors.
--load-images=[true/false] To Do Load all inlined images (default true).
--local-storage-path=/some/path Unsupported Path cannot be changed in IE.
--local-storage-quota=number Unsupported IE quota set to 10Mb per site.
 --local-to-remote-url-access=[true|false]  To Do Allows access to remote URL (default false)
--max-disk-cache-size=size  Unsupported IE does not limit cache size.
--output-encoding=encoding Ready Encoding for terminal output (default utf8).
--remote-debugger-port=number To Do Starts script in debug and listens on port
--remote-debugger-autorun=[yes|no] To Do Runs in debugger immediately (default no)
--proxy=address:port Partial Specifies the proxy server to use.
--proxy-type=[http/socks5/none] To Do Specifies the type of the proxy server.
--proxy-auth=user:passw Partial Authentication info for the proxy.
--script-encoding=encoding Ready Encoding for starting script (default utf8).
--ssl-protocol=
[sslv3|sslv2|tlsv1|any]
To Do Sets HTTPS protocol (default SSLv3).
--ssl-certificates-path= To Do Location for custom certs (default to system).
--web-security=[true/false] To Do Prevents cross-domain XHR (default true).
--webdriver Unsupported WebDriver mode (default 127.0.0.1:8910)
--webdriver-selenium-grid-hub Unsupported URL to Selenium Grid HUB (default none)
--config=/path/to/config.json To Do JSON replacement for command switches.

REPL (Interactive Mode)

You can also run TrifleJS interactively in the V8 context by executing it without any arguments.

C:\> TrifleJS.exe
triflejs> console.log(phantom.version)
{
  "major": 1,
  "minor": 7,
  "patch": 0
} 
triflejs> var keys = Object.keys(phantom.version);
triflejs> var values = keys.map(function(k) {return phantom.version[k]});
triflejs> console.log(values);
[
  1,
  7,
  0
]
triflejs> console.log(values.join('.'));
1.7.0

The REPL (Read-Eval-Print-Loop) provides a way to interactively run JavaScript and see the results. It can be used for debugging, testing, or just trying things out.

To exit the REPL just type phantom.exit() and press return.

Object: phantom

Original PhantomJS API Documentation for this section is in:

https://github.com/ariya/phantomjs/wiki/API-Reference-phantom

Feature Status Notes
Properties
.args Ready Arguments passed to the script.
.cookies Ready Get or set Cookies for any domain.
.cookiesEnabled Ready Controls whether cookies are enabled
.version Ready The version of PhantomJS instance.
.libraryPath Ready Used by .injectJs() to find scripts.
.scriptName Ready Name of the invoked script file.
Methods
.addCookie({cookie}) Partial Add a (session) Cookie to the CookieJar.
.clearCookies() Partial Delete (session) Cookies.
.deleteCookie(name) Unsupported Deletes a Cookie.
.exit(returnValue) Ready Exits program with return value.
.injectJS(filename) Ready Injects external scripts
Events
#onError Ready Global error handler

 

Module: System

Original PhantomJS API Documentation for this section is in:

https://github.com/ariya/phantomjs/wiki/API-Reference-System

Feature Status Notes
Properties
.pid Ready Current Process ID for TrifleJS process.
.platform Ready Name of platform, always phantomjs.
.os Ready Information about the operating system
.env Ready Key-value pairs of environment variables
.args Ready List of the command-line arguments

Module: WebPage

Original PhantomJS API Documentation for this section is in:

https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage

Feature Status Notes
Properties
.canGoBack Ready true if browser can navigate back.
.canGoForward Ready true if browser can navigate forward.
.clipRect To Do Page area rasterized during .render()
.content Ready HTML content of the web page.
.cookies Partial Get/set cookies visible in current URL.
.customHeaders Ready Additional HTTP headers sent to server.
.event To Do Hash object with a list of keyboard events.
.focusedFrameName Ready Name of frame IE is currently focused on.
.frameContent Ready HTML content of active frame
.frameName Ready Name of active window frame
.framePlainText Ready Plain Text body in active window frame
.frameTitle Ready Title of active window frame
.frameUrl Ready Url of active window frame
.framesCount Ready Number of frames in browser window
.framesName Ready List of names for frames in browser window.
.libraryPath Ready Used by .injectJs() to resolve script.
.navigationLocked To Do Locks navigation from page (default false)
.offlineStoragePath Unsupported Path for cache + cookies. Cannot be changed.
.offlineStorageQuota Unsupported Storage for cache + cookies. No quota in IE.
.ownsPages To Do true if current page has any child popups.
.pages To Do Array of WebPage for child popup pages.
.paperSize To Do Size of the page when rendered as PDF.
.plainText Ready Content of the web page in plain text.
.scrollPosition To Do Scroll position of the web page.
.settings To Do Various settings of the web page.
.title Ready Title of the page.
.url Ready Current URL of the web page.
.viewportSize Ready Size of viewport for the layout process.
.windowName Ready Name of the main browser window.
.zoomFactor Ready Scaling factor for rendering pages.
Methods
.addCookie({cookie}) Partial Add a (session) cookie to the current page.
.childFramesCount() Unsupported Deprecated. Use .framesCount.
.childFramesName() Unsupported Deprecated. Use .framesName.
.clearCookies() Partial Delete (session) Cookies for current domain.
.close() Ready Closes page to release memory.
.currentFrameName() Unsupported Deprecated. Use .frameName.
.deleteCookie(name) Unsupported Not supported by IE. Use .clearCookies().
.evaluate(function, arg1, arg2,..) Ready Evaluates function inside current page.
.evaluateAsync(function, ms, arg1, arg2..) Ready Async evaluate() with optional timeout.
.evaluateJavaScript(str) Ready Evaluates script in current page.
.getPage(windowName) To Do Gets a page inside a window frame.
.goBack() Ready Goes back to previous page in history
.goForward() Ready Goes forward to next page in history
.go(n) Ready Goes back or forwards by n pages in history
.includeJs(url, callback) Ready Includes script the specified url
.injectJs(filename) Ready Injects script code specified file
.open(url, callback) Ready Opens url and loads it to the page.
.open(url, method, callback) Ready As above but using a HTTP method.
.open(url, method, data, callback) Ready As above, using a HTTP method and data.
.openUrl(url, httpConf, settings) To Do Opens url with specific settings.
.release() Unsupported Deprecated. Use .close().
.reload() Ready Reloads current page.
.render(filename) Ready Renders page to specified filename
.renderBase64(format) Ready Renders page as Base64-encoded string
.sendEvent(type, [,args..]) To Do Sends mouse/keyboard event to web page.
.setContent(content, url) (v1.8) Sets .content and .url (no http request).
.stop() Ready Stops loading the current page.
.switchToFocusedFrame() Ready Switches to the frame IE is focused on
.switchToFrame(name) Ready Switches current frame by name
.switchToMainFrame() Ready Switches current frame to main window
.switchToParentFrame() Ready  Switches current frame to parent
.uploadFile(selector, path) To Do Uploads file in path to a form element
Events
#onAlert Ready Fires for alert() calls on page.
#onCallback Ready Fires for window.callPhantom calls.
#onClosing To Do Fires on window.close()
#onConfirm Ready Fires for confirm() calls on page.
#onConsoleMessage To Do Fires for console messages on page.
#onError Ready Fires when a JavaScript error occurs in the page.
#onFilePicker To Do Fires when file added to form input element.
#onInitialized Ready Fires after page created and before URL loaded
#onLoadStarted Ready Fires when page starts loading.
#onLoadFinished Ready Fires when page finishes loading.
#onNavigationRequested To Do Fires for all navigations events.
#onPageCreated To Do Fires on child page created – ie window.open().
#onPrompt Ready Fires when prompt() call made on page.
#onResourceRequested To Do Fires for all requests resources (image, css, js etc).
#onResourceReceived To Do Fires when resources are received.
#onResourceTimeout To Do Fires when resources requested time out.
#onResourceError (v1.9) Fires when error occurs loading resource.
#onUrlChanged To Do Fires whenever URL changes.

 

Module: WebServer

Original PhantomJS API Documentation for this section is in:

https://github.com/ariya/phantomjs/wiki/API-Reference-WebServer

Feature Status Notes
Properties
.port Ready TCP port on which the server listens for connections.
Methods
.listen(binding, callback) Ready Opens TCP port and executes callback for connections.
.listen(binding, opts, callback) Ready As per generic .listen() but supports Keep-Alive mode.
.close() Ready Shuts down the server.

Example

var server = require('webserver').create();
var service = server.listen(8080, function(request, response) {
    response.statusCode = 200;
    response.write('Hello!');
    response.close();
});

Request Object

Feature Status Notes
Properties
.method Ready Request method ('GET''POST', etc.)
.url Ready Path and query string part (if any) of request URL
.httpVersion Ready HTTP Protocol version
.headers Ready HTTP headers as key-value pairs
.post Ready Request body (for 'POST' / 'PUT' methods).
.postRaw Ready Raw request body (without processing form values)

Response Object

Feature Status Notes
Properties
.headers Ready HTTP headers as key-value pairs.
.statusCode Ready Sets the returned HTTP status code.
Methods
.setHeader(name, value) Ready Adds a HTTP header to response
.header(name) Ready Gets a HTTP header
.setEncoding(encoding) Ready Sets the response encoding. Default: UTF8
.write(data) Ready Sends a data chunk. Can be called multiple times.
.writeHead(statusCode, headers) Ready Sends headers to the browser.
.close() Ready Closes the HTTP connection.
.closeGracefully() Ready Same as .close() but ensures headers are sent.

 

Module: ChildProcess

PhantomJS API Documentation for this section is in:

http://phantomjs.org/api/child_process/

Note that the original PhantomJS child_process module was left unfinished, there is some additional functionality below that attempts to complete work on the API.

Feature Status Notes
Methods
.spawn(path, [args]) Ready Invoke process and listen on stdout/stderr.
.execFile(path, [args], opts, function) Ready Invoke subprocess and execute callback.
.execSync(path, [args], opts) Ready Invoke subprocess and waits for exit.
.terminate() Ready Terminates all running child processes.

Example

var child_process = require("child_process");
var context = child_process.execFile("dir", ["/a:h","C:\\"], null,
  function (err, stdout, stderr) {
    console.log("execFileSTDOUT:", stdout)
    console.log("execFileSTDERR:", stderr)
    console.log("context.exitCode", context.exitCode);
});

Context Object

This object is returned by child_process methods. It represents the execution context for each child process.

Feature Status Notes
Properties
.exited Ready true if the process has completed execution
.exitCode Ready Usually 0 if successful.
.output Ready Console output generated by child process.
.errorOutput Ready Error output generated by child process.
.stdout Ready Lightweight Stream object for console standard output.
.stderr Ready Lightweight Stream object for console standard error.
Methods
.kill() Ready Terminates process and disposes of memory allocation.
Events
#onStdOut Ready Fires when data is outputted to stdout.
#onStdErr Ready Fires when data is outputted to stderr.
#onExit Ready Fires when the process terminates.

Note on Event Handling:

The Context object event handlers have been created in a very flexible format, allowing for the variations that appear in the PhantomJS child_process API, a simplification of the same, and the event handling conventions used elsewhere in the PhantomJS project.

As per PhantomJS child_process API definition:

var context = child_process.spawn('triflejs.exe', ['--help']);
context.stdout.on('data', function(data) { console.log(data); });
context.stdout.on('data', function(data) { console.error(data); });
context.on('exit', function(code) { phantom.exit(code); });

Here is the (recommended) simplified version:

var context = child_process.spawn('triflejs.exe', ['--help']);
context.on('stdout', function(data) { console.log(data); });
context.on('stderr', function(data) { console.error(data); });
context.on('exit', function(code) { phantom.exit(code); });

Or alternatively (as used in the Phantom object and WebPage module):

var context = child_process.spawn('triflejs.exe', ['--help']);
context.onStdOut = function(data) { console.log(data); };
context.onStdErr = function(data) { console.error(data); };
context.onExit = function(code) { phantom.exit(code); };

An ECMAv5 javascript setter is used in the last example to avoid overwriting a previously defined event listener/callback. To clear all listeners for a particular event just use context.onExit = null;.

New Features

These are additional features added into TrifleJS that are not present in PhantomJS.

Feature Status Notes
COMMAND LINE
--unit-test or -u Partial Runs a full system test.
--clear-cache Ready Clears IE cache history before starting.
--secure-mode Ready Disables ChildProcess and FileSystem modules.
--ignore-popups Ready Ignores Window Popups.
--emulate=(version) Ready Emulates specific IE versions.
--render=(url) Ready Renders a URL to file and quits.
Object: trifle
.version Ready Version of TrifleJS
.emulation Ready Target IE Version for Emulation (set using --emulate=IE9).
.wait(ms) Ready Pauses execution for n milliseconds.

 

YOU TOO CAN HELP

TrifleJS needs YOU

We need your input to keep improving!
Send code samples and bug reports to:
https://github.com/sdesalas/trifleJS/issues


Download

This code is still very much in beta. Check again for updates.

icon_zipStable v0.4 icon_zipLatest Beta v0.5

If you are not sure which version to use then download the ‘Stable’ version.

Roadmap

  • v0.3 – 56% of PhantomJS API – Release Notes
  • v0.4 – 72% of PhantomJS API – Release Notes
  • v0.5(work in progress…)
  • v0.6 – 100% of PhantomJS non-WebPage modules, 80% of WebPage module API
  • v0.7 – 100% of PhantomJS Core API (v1.7) + internal unit tests
  • v0.8CasperJS Support (implement Test suite and fixes)
  • v0.9 – Testing and Support for Windows platforms (after XP SP2).
  • v1.0 – Only minor Bugfixes left
  • v1.1 – Nice to haves (WebDriver, improved IPC, REPL Autocompletion etc)
Steven de Salas

Steven de Salas

Steven de Salas is a freelance application developer based in Hobart, Tasmania. He is the main contributor of the TrifleJS project.

 

 

Razvan Radu

Razvan Radu

Razvan is a designer based in Bucharest, Romania. He specializes in logo and web design and has contributed the TrifleJS “trifle” logo to this project.