puppeteer/examples/puppeteer-in-browser/main.mjs
2024-04-29 10:58:20 +00:00

24 lines
535 B
JavaScript

/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
// TODO: can rollup find the browser entrypoint?
import puppeteer from 'puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js';
async function onConnectClick() {
const wsUrl = document.querySelector('#ws').value;
const browser = await puppeteer.connect({
browserWSEndpoint: wsUrl,
});
alert('Browser has ' + (await browser.pages()).length + ' pages');
browser.disconnect();
}
globalThis.onConnectClick = onConnectClick;