Skip to content

Instantly share code, notes, and snippets.

@mtsmfm
Last active September 26, 2024 07:15
Show Gist options
  • Save mtsmfm/8775b0f10264f028893958c83e3083ea to your computer and use it in GitHub Desktop.
Save mtsmfm/8775b0f10264f028893958c83e3083ea to your computer and use it in GitHub Desktop.
Playwright throws Function not exposed error
import { chromium } from "playwright"
import { fork } from "node:child_process"
const main = async () => {
if (process.argv[2] === "child") {
await chromium.connectOverCDP("http://localhost:12345")
} else {
const browser = await chromium.launch({
args: ["--remote-debugging-port=12345"],
headless: false
})
const context = await browser.newContext()
context.exposeBinding("hello", async ({}) => {})
const page = await context.newPage()
page.on("pageerror", (error) => {
console.log(error)
})
await page.evaluate(() => {
setInterval(() => {
;(window as any).hello()
}, 500)
})
const controller = new AbortController()
const { signal } = controller
fork(__filename, ["child"], { signal })
await page.pause()
controller.abort()
await context.close()
await browser.close()
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment