Skip to content

Instantly share code, notes, and snippets.

@philbritton
Forked from nesteruk/SharpKitPhantomJS
Created February 10, 2014 01:30
Show Gist options
  • Save philbritton/8908802 to your computer and use it in GitHub Desktop.
Save philbritton/8908802 to your computer and use it in GitHub Desktop.
using SharpKit.JavaScript;
namespace PhantomJS
{
[JsType(JsMode.Prototype, Export = false, Name = "console")]
public static class Console
{
public static void log(string message) {}
}
[JsType(JsMode.Prototype, Export=false, Name = "require")]
public static class Require
{
[JsMethod(Name="require", Global = true)]
public static JsObject Module(string moduleName)
{
return null;
}
}
[JsType(JsMode.Prototype, Export=false)]
public class FileSystem
{
public string separator { get; private set; }
public string workingDirectory { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="path"></param>
/// <param name="content"></param>
/// <param name="mode">w for write or a for append</param>
public void write(string path, string content, string mode) {}
public JsString read(string path) { return null; }
}
[JsType(JsMode.Prototype, Export=false, Name = "phantom")]
public static class Phantom
{
/// <summary>
/// This read-only property is an array of the arguments passed to the script.
/// </summary>
public static JsArray args { get; private set; }
/// <summary>
/// This property stores the path which is used by injectJs function to resolve the script name. Initially it is set to the location of the script invoked by PhantomJS.
/// </summary>
public static JsString libraryPath { get; private set; }
/// <summary>
/// This read-only property stores the name of the invoked script file.
/// </summary>
public static JsString scriptName { get; private set; }
/// <summary>
/// This read-only property holds PhantomJS version. Example value: { major:1, minor:0, patch:0 }.
/// </summary>
public static JsObject version { get; private set; }
/// <summary>
/// Exits the program with the specified return value. If no return value is specified, it is set to 0.
/// </summary>
[JsMethod]
public static int exit(int returnValue = 0) { return returnValue; }
/// <summary>
/// Injects external script code from the specified file. If the file can not be found in the current directory, <see cref="libraryPath"/> is used for additional look up.
/// This function returns true if injection is successful, otherwise it returns false.
/// </summary>
/// <param name="filename"></param>
[JsMethod]
public static bool injectJs(string filename) { return true; }
}
[JsType(JsMode.Json)]
public class Rectangle
{
public int top { get; set; }
public int left { get; set; }
public int width { get; set; }
public int height { get; set; }
}
[JsType(JsMode.Json)]
public class Size
{
public int width { get; set; }
public int height { get; set; }
}
[JsType(JsMode.Global, Export=false, Name = "WebPage")]
public class WebPage
{
public Rectangle clipRect { get; set; }
public string content { get; set; }
public string libraryPath { get; set; }
public Settings settings { get; set; }
public Size viewportSize { get; set; }
public JsObject evaluate(JsFunc<JsObject> function) { return null; }
public void includeJs(JsString url, JsAction callback) { }
public bool injectJs(JsString filename) { return false; }
public void open(JsString url, JsAction<string> callback) { }
public void render(JsString filename) { }
public void sendEvent(string type, params JsObject[] pars) { }
public void uploadFile(string selector, string fileName) { }
public void onAlert(JsAction<string> message) { }
public void onConsoleMessage(JsAction<string, int, string> messageLineSource) { }
public void onInitialized(JsAction callback) { }
public void onLoadFinished(JsAction<string> status) { }
public void onLoadStarted(JsAction callback) { }
public void onResourceRequested(JsAction<JsObject> resource) { }
public void onResourceReceived(JsAction<JsObject> requestObject) { }
}
[JsType(JsMode.Json)]
public class Settings
{
public bool javascriptEnabled { get; set; }
public bool loadImages { get; set; }
public bool loadPlugins { get; set; }
public bool localToRemoteUrlAccessEnabled { get; set; }
public string userAgent { get; set; }
public string userName { get; set; }
public string password { get; set; }
public bool XSSAuditingEnabled { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment