Last active
September 26, 2024 07:15
-
-
Save mtsmfm/8775b0f10264f028893958c83e3083ea to your computer and use it in GitHub Desktop.
Playwright throws Function not exposed error
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
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