fix: connectConsole should disconnect on page close

This commit is contained in:
orion 2023-10-10 10:40:51 -05:00
parent 459a3ce3c9
commit 53d46a5c1e
Signed by: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -18,7 +18,7 @@ module Puppeteer.Page.Event
import Prelude import Prelude
import Control.Monad.Error.Class (liftEither) import Control.Monad.Error.Class (liftEither, try)
import Control.Monad.Except (runExcept) import Control.Monad.Except (runExcept)
import Data.Bifunctor (lmap) import Data.Bifunctor (lmap)
import Data.Either (hush, note) import Data.Either (hush, note)
@ -32,7 +32,7 @@ import Effect.Console as Console
import Effect.Exception (Error, error) import Effect.Exception (Error, error)
import Effect.Unsafe (unsafePerformEffect) import Effect.Unsafe (unsafePerformEffect)
import Foreign (Foreign, unsafeFromForeign) import Foreign (Foreign, unsafeFromForeign)
import Puppeteer.Base (Context(..), Frame, Page) import Puppeteer.Base (Context(..), Frame, Page, closeContext)
import Puppeteer.HTTP as HTTP import Puppeteer.HTTP as HTTP
import Puppeteer.Page as Page import Puppeteer.Page as Page
import Puppeteer.Page.Event.ConsoleMessage (ConsoleMessage, messageTypeString) import Puppeteer.Page.Event.ConsoleMessage (ConsoleMessage, messageTypeString)
@ -55,7 +55,10 @@ connectPageConsole p =
ConsoleMessage.Warning -> Console.warn text ConsoleMessage.Warning -> Console.warn text
_ -> Console.log text _ -> Console.log text
in in
void $ listen Console onmsg p launchAff_ do
stop <- liftEffect $ listen Console (void <<< try <<< onmsg) p
once Close p
closeContext stop
data UnitEvent data UnitEvent
= Close = Close