// Type definitions for PhantomJS bridge for NodeJS 3.2 // Project: https://github.com/sgentle/phantomjs-node // Definitions by: horiuchi , Random // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export function create(args?: string[], config?: { phantomPath?: string, shimPath?: string, logger?: { info?: winstonLeveledLogMethod, debug?: winstonLeveledLogMethod, error?: winstonLeveledLogMethod, warn?: winstonLeveledLogMethod, }, logLevel?: 'debug' | 'info' | 'warn' | 'error', }): Promise; export interface winstonLeveledLogMethod { (message: string, callback: (...args: any[]) => void): any; (message: string, meta: any, callback: (...args: any[]) => void): any; (message: string, ...meta: any[]): any; (infoObject: any): any; } export interface PhantomJS { callback(fn: (pageNum: number, numPages: number) => string): IPhantomCallback; createPage(): Promise; exit(returnValue?: number): void; } export interface WebPage { open(url: string): Promise; open(url: string, settings: IOpenWebPageSettings): Promise; on(event: 'onResourceRequested', runOnPhantom: false, listener: (requestData: IRequestData, networkRequest: { abort: () => void, changeUrl: (newUrl: string) => void, setHeader: (key: string, value: string) => void }) => void): Promise<{ pageId: string }>; on(event: 'onResourceRequested', listener: (requestData: IRequestData, networkRequest: { abort: () => void, changeUrl: (newUrl: string) => void, setHeader: (key: string, value: string) => void }) => void): Promise<{ pageId: string }>; on(event: 'onLoadFinished', runOnPhantom: false, listener: (status: 'success' | 'fail') => void): Promise<{ pageId: string }>; on(event: 'onLoadFinished', listener: (status: 'success' | 'fail') => void): Promise<{ pageId: string }>; on(event: 'onAlert', runOnPhantom: false, listener: (msg: string) => void): Promise<{ pageId: string }>; on(event: 'onAlert', listener: (msg: string) => void): Promise<{ pageId: string }>; on(event: 'onCallback', runOnPhantom: false, listener: (data: any) => void): Promise<{ pageId: string }>; on(event: 'onCallback', listener: (data: any) => void): Promise<{ pageId: string }>; on(event: 'onClosing', runOnPhantom: false, listener: (closingPage: any) => void): Promise<{ pageId: string }>; on(event: 'onClosing', listener: (closingPage: any) => void): Promise<{ pageId: string }>; on(event: 'onConfirm', runOnPhantom: false, listener: (msg: string) => void): Promise<{ pageId: string }>; on(event: 'onConfirm', listener: (msg: string) => void): Promise<{ pageId: string }>; on(event: 'onConsoleMessage', runOnPhantom: false, listener: (msg: string, lineNum: number, sourceId: string) => void): Promise<{ pageId: string }>; on(event: 'onConsoleMessage', listener: (msg: string, lineNum: number, sourceId: string) => void): Promise<{ pageId: string }>; on(event: 'onError', runOnPhantom: false, listener: (msg: string, trace: { file: string, line: string, function: string }[]) => void): Promise<{ pageId: string }>; on(event: 'onError', listener: (msg: string, trace: { file: string, line: string, function: string }[]) => void): Promise<{ pageId: string }>; on(event: 'onFilePicker', runOnPhantom: false, listener: (oldFile: any) => void): Promise<{ pageId: string }>; on(event: 'onFilePicker', listener: (oldFile: any) => void): Promise<{ pageId: string }>; on(event: 'onInitialized', runOnPhantom: false, listener: () => void): Promise<{ pageId: string }>; on(event: 'onInitialized', listener: () => void): Promise<{ pageId: string }>; on(event: 'onLoadStarted', runOnPhantom: false, listener: () => void): Promise<{ pageId: string }>; on(event: 'onLoadStarted', listener: () => void): Promise<{ pageId: string }>; on(event: 'onNavigationRequested', runOnPhantom: false, listener: (url: string, type: 'Undefined' | 'LinkClicked' | 'FormSubmitted' | 'BackOrForward' | 'Reload' | 'FormResubmitted' | 'Other', willNavigate: boolean, main: boolean) => void): Promise<{ pageId: string }>; on(event: 'onNavigationRequested', listener: (url: string, type: 'Undefined' | 'LinkClicked' | 'FormSubmitted' | 'BackOrForward' | 'Reload' | 'FormResubmitted' | 'Other', willNavigate: boolean, main: boolean) => void): Promise<{ pageId: string }>; on(event: 'onPageCreated', runOnPhantom: false, listener: (newPage: any) => void): Promise<{ pageId: string }>; on(event: 'onPageCreated', listener: (newPage: any) => void): Promise<{ pageId: string }>; on(event: 'onPrompt', runOnPhantom: false, listener: (msg: string, defaultVal: string) => void): Promise<{ pageId: string }>; on(event: 'onPrompt', listener: (msg: string, defaultVal: string) => void): Promise<{ pageId: string }>; on(event: 'onResourceError', runOnPhantom: false, listener: (resourceError: { id: string, url: string, errorCode: number, errorString: string }) => void): Promise<{ pageId: string }>; on(event: 'onResourceError', listener: (resourceError: { id: string, url: string, errorCode: number, errorString: string }) => void): Promise<{ pageId: string }>; on(event: 'onResourceReceived', runOnPhantom: false, listener: (response: IResponse) => void): Promise<{ pageId: string }>; on(event: 'onResourceReceived', listener: (response: IResponse) => void): Promise<{ pageId: string }>; on(event: 'onResourceTimeout', runOnPhantom: false, listener: (request: IRequestData & { errorCode: number, errorString: string }) => void): Promise<{ pageId: string }>; on(event: 'onResourceTimeout', listener: (request: IRequestData & { errorCode: number, errorString: string }) => void): Promise<{ pageId: string }>; on(event: 'onUrlChanged', runOnPhantom: false, listener: (targetUrl: string) => void): Promise<{ pageId: string }>; on(event: 'onUrlChanged', listener: (targetUrl: string) => void): Promise<{ pageId: string }>; off(event: 'onResourceRequested' | 'onLoadFinished' | 'onAlert' | 'onCallback' | 'onClosing' | 'onConfirm' | 'onConsoleMessage' | 'onError' | 'onFilePicker' | 'onInitialized' | 'onLoadStarted' | 'onNavigationRequested' | 'onPageCreated' | 'onPrompt' | 'onResourceError' | 'onResourceReceived' | 'onResourceTimeout' | 'onUrlChanged'): Promise<{ pageId: string }>; close(): Promise; evaluate(callback: () => R): Promise; evaluate(callback: (arg: T) => R, arg: T): Promise; evaluate(callback: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): Promise; evaluate(callback: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: T3): Promise; evaluate(callback: (...args: any[]) => R, ...args: any[]): Promise; includeJs(url: string): Promise; injectJs(filename: string): Promise; sendEvent(mouseEventType: string, mouseX?: number, mouseY?: number, button?: string): Promise; sendEvent(keyboardEventType: string, key: string, null1?: void, null2?: void, modifier?: number): Promise; render(filename: string): Promise; render(filename: string, options?: { format?: string; quality?: string; }): Promise; renderBase64(type: string): Promise; setContent(html: string, url: string): Promise; property(key: 'content' | 'plainText' | 'focusedFrameName' | 'frameContent' | 'frameName' | 'framePlainText' | 'frameTitle' | 'libraryPath' | 'offlineStoragePath' | 'title' | 'url' | 'windowName'): Promise; property(key: 'framesName' | 'pagesWindowName' | 'pages'): Promise; property(key: 'canGoBack' | 'canGoForward' | 'navigationLocked' | 'ownsPages'): Promise; property(key: 'framesCount' | 'offlineStorageQuota' | 'zoomFactor'): Promise; property(key: 'clipRect'): Promise<{ top: number, left: number, width: number, height: number }>; property(key: 'cookies'): Promise; property(key: 'customHeaders'): Promise<{ [key: string]: string }>; property(key: 'paperSize'): Promise; property(key: 'scrollPosition'): Promise<{ top: number, left: number }>; property(key: 'viewportSize'): Promise<{ width: number, height: number }>; property(key: string): Promise; property(key: string, value: T): Promise; setting(key: 'javascriptEnabled' | 'loadImages' | 'localToRemoteUrlAccessEnabled' | 'XSSAuditingEnabled' | 'webSecurityEnabled'): Promise; setting(key: 'userAgent' | 'userName' | 'password'): Promise; setting(key: 'resourceTimeout'): Promise; setting(key: string): Promise; setting(key: string, value: T): Promise; addCookie(cookie: ICookie): Promise; deleteCookie(cookieName: string): Promise; clearCookies(): Promise; } export interface ICookie { name: string, value: string, domain?: string, path: string, httponly?: boolean, secure?: boolean, expires?: string } export interface IPaperSizeOptions { width?: string; height?: string; format?: 'A3' | 'A4' | 'A5' | 'Legal' | 'Letter' | 'Tabloid'; orientation?: 'portrait' | 'landscape'; margin?: string | { top?: string; left?: string; bottom?: string; right?: string; }; header?: { height: string, contents: IPhantomCallback }; footer?: { height: string; contents: IPhantomCallback }; } export interface IOpenWebPageSettings { operation?: 'GET' | 'POST' | 'HEAD' | 'DELETE' | 'PUT' | string; encoding?: 'utf8' | string; headers?: { [s: string]: string }; data?: string; } /** * The phantom.callback object */ export interface IPhantomCallback { transform: true; target: Function; method: 'callback'; parent: 'phantom' } export interface IResponse { id: string; url: string; time: Date; headers: { name: string, value: string }[]; bodySize: number; contentType: string; redirectURL: string; stage: 'start' | 'end'; status: number; statusText: string; } export interface IRequestData { id: number; method: string; url: string; time: Date; headers: { name: string, value: string }[]; }