From bf075f9628a50019359cda2830e1a1fcf71589ad Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Sun, 8 Oct 2023 12:10:00 -0500 Subject: [PATCH] fix: createCDPSession --- src/Puppeteer.Page.js | 5 ++++- src/Puppeteer.Page.purs | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Puppeteer.Page.js b/src/Puppeteer.Page.js index 993cbbf..30a869f 100644 --- a/src/Puppeteer.Page.js +++ b/src/Puppeteer.Page.js @@ -1,4 +1,4 @@ -import { BrowserContext } from 'puppeteer' +import { BrowserContext, CDPSession } from 'puppeteer' import { Keyboard } from 'puppeteer' import { Mouse } from 'puppeteer' import { Touchscreen } from 'puppeteer' @@ -18,6 +18,9 @@ export const touchscreen = p => () => p.touchscreen /** @type {(_: Browser | BrowserContext) => () => Promise} */ export const _newPage = b => () => b.newPage() +/** @type {(_: Page) => () => Promise} */ +export const _createCDPSession = p => () => p.createCDPSession() + /** @type {(_: Browser | BrowserContext) => () => Promise>} */ export const _all = b => () => b.pages() diff --git a/src/Puppeteer.Page.purs b/src/Puppeteer.Page.purs index 913ff7f..b8bd9ef 100644 --- a/src/Puppeteer.Page.purs +++ b/src/Puppeteer.Page.purs @@ -1,5 +1,6 @@ module Puppeteer.Page ( module X + , createCDPSession , authenticate , new , all @@ -40,7 +41,7 @@ import Effect.Aff (Aff) import Foreign (Foreign, unsafeToForeign) import Node.Path (FilePath) import Puppeteer.Base (Page) as X -import Puppeteer.Base (class PageProducer, Handle, Keyboard, LifecycleEvent, Page, URL, Viewport, duplexLifecycleEvent, duplexViewport, duplexWrite) +import Puppeteer.Base (class PageProducer, CDPSession, Handle, Keyboard, LifecycleEvent, Page, URL, Viewport, duplexLifecycleEvent, duplexViewport, duplexWrite) import Puppeteer.Handle (unsafeCoerceHandle) import Puppeteer.Selector (class Selector, toCSS) import Simple.JSON (readImpl, undefined, writeImpl) @@ -103,6 +104,7 @@ foreign import mouse :: Page -> Effect Unit foreign import touchscreen :: Page -> Effect Unit foreign import isClosed :: Page -> Effect Boolean +foreign import _createCDPSession :: Page -> Effect (Promise CDPSession) foreign import _authenticate :: { username :: String, password :: String } -> Page -> Effect (Promise Unit) foreign import _newPage :: Foreign -> Effect (Promise Page) foreign import _all :: Foreign -> Effect (Promise (Array Page)) @@ -120,6 +122,9 @@ foreign import _viewport :: Page -> Foreign new :: forall b. PageProducer b => b -> Aff Page new = Promise.toAffE <<< _newPage <<< unsafeToForeign +createCDPSession :: Page -> Aff CDPSession +createCDPSession = Promise.toAffE <<< _createCDPSession + authenticate :: { username :: String, password :: String } -> Page -> Aff Unit authenticate creds = Promise.toAffE <<< _authenticate creds