-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add type declarations and export some DOM impl (#198)
Co-authored-by: Pål Edman <[email protected]>
- Loading branch information
1 parent
91aeb63
commit 486f8f5
Showing
5 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { CookieJar } from 'cookiejar'; | ||
import { Response as FetchResponse } from 'node-fetch-commonjs'; | ||
|
||
declare global { | ||
interface Window { | ||
prototype: Window; | ||
} | ||
interface Document { | ||
prototype: Document; | ||
} | ||
interface MutationObserver { | ||
prototype: Document; | ||
new(callback: MutationCallback): MutationObserver; | ||
} | ||
} | ||
|
||
export class BrowserTab { | ||
/** Cheerio context */ | ||
get $(): cheerio.Cheerio; | ||
get jar(): CookieJar; | ||
get response(): FetchResponse; | ||
window: Window; | ||
document: Document; | ||
navigateTo(uri: string, headers?: Record<string, any>, statusCode?: number): Promise<BrowserTab>; | ||
load(markup: string): BrowserTab; | ||
focusIframe(element: HTMLElement, src: string): Promise<BrowserTab>; | ||
runScript(script: HTMLElement): void; | ||
runScripts(context?: Node): void; | ||
mutated(targetNode: Node, config?: { childList?: boolean, attributes?: boolean }): Promise<any[]>; | ||
} | ||
|
||
export class WebPage { | ||
navigateTo(uri: string, headers?: Record<string, any>, statusCode?: number): Promise<BrowserTab>; | ||
load(markup: string): BrowserTab; | ||
submit(uri: string, options?: Record<string, any>): Promise<BrowserTab>; | ||
fetch(uri: string, requestOptions?: Record<string, any>): Promise<FetchResponse>; | ||
} | ||
|
||
export class Browser { | ||
constructor(origin: any, options?: Record<string, any>); | ||
constructor(options?: Record<string, any>); | ||
navigateTo(uri: string, headers?: Record<string, any>, statusCode?: number): Promise<BrowserTab>; | ||
load(markup: string): WebPage; | ||
} | ||
|
||
interface DOMInterface { | ||
Document: Document; | ||
HTMLCollection: HTMLCollection; | ||
IntersectionObserver: IntersectionObserver; | ||
MutationObserver: MutationObserver; | ||
Window: Window; | ||
Storage: Storage; | ||
} | ||
|
||
export const DOM: DOMInterface; | ||
|
||
export default Browser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters