forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phantomjs.d.ts
308 lines (275 loc) · 8.28 KB
/
phantomjs.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// Type definitions for PhantomJS v1.9.0 API
// Project: https://github.com/ariya/phantomjs/wiki/API-Reference
// Definitions by: Jed Hunsaker <https://github.com/jedhunsaker>, Mike Keesey <https://github.com/keesey>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare function require(module: string): any;
declare var phantom: Phantom;
interface Phantom {
// Properties
args: string[]; // DEPRECATED
cookies: Cookie[];
cookiesEnabled: boolean;
libraryPath: string;
scriptName: string; // DEPRECATED
version: {
major: number;
minor: number;
patch: number;
};
// Functions
addCookie(cookie: Cookie): boolean;
clearCookies(): void;
deleteCookie(cookieName: string): boolean;
exit(returnValue?: any): boolean;
injectJs(filename: string): boolean;
// Callbacks
onError: (msg: string, trace: string[]) => any;
}
interface System {
pid: number;
platform: string;
os: {
architecture: string;
name: string;
version: string;
};
env: { [name: string]: string; };
args: string[];
}
interface WebPage {
// Properties
canGoBack: boolean;
canGoForward: boolean;
clipRect: ClipRect;
content: string;
cookies: Cookie[];
customHeaders: { [name: string]: string; };
event: any; // :TODO: elaborate this when documentation improves
focusedFrameName: string;
frameContent: string;
frameName: string;
framePlainText: string;
frameTitle: string;
frameUrl: string;
framesCount: number;
framesName: any; // :TODO: elaborate this when documentation improves
libraryPath: string;
navigationLocked: boolean;
offlineStoragePath: string;
offlineStorageQuota: number;
ownsPages: boolean;
pages: WebPage[];
pagesWindowName: string;
paperSize: PaperSize;
plainText: string;
scrollPosition: TopLeft;
settings: WebPageSettings;
title: string;
url: string;
viewportSize: Size;
windowName: string;
zoomFactor: number;
// Functions
addCookie(cookie: Cookie): boolean;
childFramesCount(): number; // DEPRECATED
childFramesName(): string; // DEPRECATED
clearCookies(): void;
close(): void;
currentFrameName(): string; // DEPRECATED
deleteCookie(cookieName: string): boolean;
evaluate(fn: Function, ...args: any[]): any;
evaluateAsync(fn: Function): void;
evaluateJavascript(str: string): any; // :TODO: elaborate this when documentation improves
getPage(windowName: string): WebPage;
go(index: number): void;
goBack(): void;
goForward(): void;
includeJs(url: string, callback: Function): void;
injectJs(filename: string): boolean;
open(url: string, callback: (status: string) => any): void;
open(url: string, method: string, callback: (status: string) => any): void;
open(url: string, method: string, data: any, callback: (status: string) => any): void;
openUrl(url: string, httpConf: any, settings: any): void; // :TODO: elaborate this when documentation improves
release(): void; // DEPRECATED
reload(): void;
render(filename: string): void;
renderBase64(format: string): string;
sendEvent(mouseEventType: string, mouseX?: number, mouseY?: number, button?: string): void;
sendEvent(keyboardEventType: string, keyOrKeys: any, aNull?: any, bNull?: any, modifier?: number): void;
setContent(content: string, url: string): void;
stop(): void;
switchToFocusedFrame(): void;
switchToFrame(frameName: string): void;
switchToFrame(framePosition: number): void;
switchToChildFrame(frameName: string): void;
switchToChildFrame(framePosition: number): void;
switchToMainFrame(): void; // DEPRECATED
switchToParentFrame(): void; // DEPRECATED
uploadFile(selector: string, filename: string): void;
// Callbacks
onAlert: (msg: string) => any;
onCallback: Function; // EXPERIMENTAL
onClosing: (closingPage: WebPage) => any;
onConfirm: (msg: string) => boolean;
onConsoleMessage: (msg: string, lineNum?: number, sourceId?: string) => any;
onError: (msg: string, trace: string[]) => any;
onFilePicker: (oldFile: string) => string;
onInitialized: () => any;
onLoadFinished: (status: string) => any;
onLoadStarted: () => any;
onNavigationRequested: (url: string, type: string, willNavigate: boolean, main: boolean) => any;
onPageCreated: (newPage: WebPage) => any;
onPrompt: (msg: string, defaultVal: string) => string;
onResourceError: (resourceError: ResourceError) => any;
onResourceReceived: (response: ResourceResponse) => any;
onResourceRequested: (requestData: ResourceRequest, networkRequest: NetworkRequest) => any;
onUrlChanged: (targetUrl: string) => any;
// Callback triggers
closing(closingPage: WebPage): void;
initialized(): void;
javaScriptAlertSent(msg: string): void;
javaScriptConsoleMessageSent(msg: string, lineNum?: number, sourceId?: string): void;
loadFinished(status: string): void;
loadStarted(): void;
navigationRequested(url: string, type: string, willNavigate: boolean, main: boolean): void;
rawPageCreated(newPage: WebPage): void;
resourceReceived(response: ResourceResponse): void;
resourceRequested(requestData: ResourceRequest, networkRequest: NetworkRequest): void;
urlChanged(targetUrl: string): void;
}
interface ResourceError {
id: number;
url: string;
errorCode: string;
errorString: string;
}
interface ResourceResponse {
id: number;
url: string;
time: Date;
headers: { [name: string]: string; };
bodySize: number;
contentType?: string;
redirectURL?: string;
stage: string;
status: number;
statusText: string;
}
interface ResourceRequest {
id: number;
method: string;
url: string;
time: Date;
headers: { [name: string]: string; };
}
interface NetworkRequest {
abort(): void;
changeUrl(url: string): void;
setHeader(name: string, value: string): void;
}
interface PaperSize {
width?: string;
height?: string;
border: string;
format?: string;
orientation?: string;
}
interface WebPageSettings {
javascriptEnabled: boolean;
loadImages: boolean;
localToRemoteUrlAccessEnabled: boolean;
userAgent: string;
userName: string;
password: string;
XSSAuditingEnabled: boolean;
webSecurityEnabled: boolean;
resourceTimeout: number;
}
interface FileSystem {
// Properties
separator: string;
workingDirectory: string;
// Functions
// Query Functions
list(path: string): string[];
absolute(path: string): string;
exists(path: string): boolean;
isDirectory(path: string): boolean;
isFile(path: string): boolean;
isAbsolute(path: string): boolean;
isExecutable(path: string): boolean;
isReadable(path: string): boolean;
isWritable(path: string): boolean;
isLink(path: string): boolean;
readLink(path: string): string;
// Directory Functions
changeWorkingDirectory(path: string): void;
makeDirectory(path: string): void;
makeTree(path: string): void;
removeDirectory(path: string): void;
removeTree(path: string): void;
copyTree(source: string, destination: string): void;
// File Functions
open(path: string, mode: string): Stream;
open(path: string, options: { mode: string; charset?: string; }): Stream;
read(path: string): string;
write(path: string, content: string, mode: string): void;
size(path: string): number;
remove(path: string): void;
copy(source: string, destination: string): void;
move(source: string, destination: string): void;
touch(path: string): void;
}
interface Stream {
atEnd(): boolean;
close(): void;
flush(): void;
read(): string;
readLine(): string;
seek(position: number): void;
write(data: string): void;
writeLine(data: string): void;
}
interface WebServer {
port: number;
listen(port: number, cb?: (request: WebServerRequest, response: WebServerResponse) => void): boolean;
listen(ipAddressPort: string, cb?: (request: WebServerRequest, response: WebServerResponse) => void): boolean;
close(): void;
}
interface WebServerRequest {
method: string;
url: string;
httpVersion: number;
headers: { [name: string]: string; };
post: string;
postRaw: string;
}
interface WebServerResponse {
headers: { [name: string]: string; };
setHeader(name: string, value: string): void;
header(name: string): string;
statusCode: number;
setEncoding(encoding: string): void;
write(data: string): void;
writeHead(statusCode: number, headers?: { [name: string]: string; }): void;
close(): void;
closeGracefully(): void;
}
interface TopLeft {
top: number;
left: number;
}
interface Size {
width: number;
height: number;
}
interface ClipRect extends TopLeft, Size {
}
interface Cookie {
name: string;
value: string;
domain?: string;
}
declare module "webpage" {
export function create(): WebPage;
}