diff --git a/types/puppeteer/index.d.ts b/types/puppeteer/index.d.ts index 8479c100a1..2c803966db 100644 --- a/types/puppeteer/index.d.ts +++ b/types/puppeteer/index.d.ts @@ -202,7 +202,7 @@ export interface BoundingBox { } export interface ElementHandle extends JSHandle { - boundingBox(): BoundingBox; + boundingBox(): BoundingBox | null; click(options?: ClickOptions): Promise; focus(): Promise; hover(): Promise; @@ -227,7 +227,7 @@ export interface ExecutionContext { } export interface JSHandle { - asElement(): ElementHandle; + asElement(): ElementHandle | null; dispose(): Promise; executionContext(): ExecutionContext; getProperties(): Promise>; @@ -305,7 +305,7 @@ export interface Response { } export interface FrameBase { - $(selector: string): Promise; + $(selector: string): Promise; $$(selector: string): Promise; $$eval( selector: string, @@ -349,7 +349,7 @@ export interface Frame extends FrameBase { executionContext(): ExecutionContext; isDetached(): boolean; name(): string; - parentFrame(): Frame | undefined; + parentFrame(): Frame | null; } export interface EventObj { @@ -396,9 +396,9 @@ export interface Page extends FrameBase { focus(selector: string): Promise; frames(): Frame[]; getMetrics(): Metrics; - goBack(options?: Partial): Promise; - goForward(options?: Partial): Promise; - goto(url: string, options?: Partial): Promise; + goBack(options?: Partial): Promise; + goForward(options?: Partial): Promise; + goto(url: string, options?: Partial): Promise; hover(selector: string): Promise; keyboard: Keyboard; mainFrame(): Frame; diff --git a/types/puppeteer/puppeteer-tests.ts b/types/puppeteer/puppeteer-tests.ts index 9d76178a62..57580f1561 100644 --- a/types/puppeteer/puppeteer-tests.ts +++ b/types/puppeteer/puppeteer-tests.ts @@ -151,7 +151,7 @@ puppeteer.launch().then(async browser => { }); const inputElement = await page.$("input[type=submit]"); - await inputElement.click(); + if (inputElement) await inputElement.click(); }); // Example with launch options @@ -178,9 +178,9 @@ puppeteer.launch().then(async browser => { } }); const page = await browser.newPage(); - const button = await page.$("#myButton"); - const div = await page.$("#myDiv"); - const input = await page.$("#myInput"); + const button = (await page.$("#myButton"))!; + const div = (await page.$("#myDiv"))!; + const input = (await page.$("#myInput"))!; await page.addStyleTag({ url: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" @@ -223,7 +223,7 @@ puppeteer.launch().then(async browser => { console.log(navResponse.ok, navResponse.status, navResponse.url, navResponse.headers); // evaluate example - const bodyHandle = await page.$('body'); + const bodyHandle = (await page.$('body'))!; const html = await page.evaluate(body => body.innerHTML, bodyHandle); await bodyHandle.dispose();