import { PuppeteerExtraPlugin } from '@zorilla/puppeteer-extra-plugin'; import type { Browser, Page } from '@zorilla/puppeteer-extra-plugin/puppeteer'; import * as RemoteDevTools from './lib/RemoteDevTools.js'; interface AuthCredentials { user: string; pass: string; } interface PluginOptions { prefix?: string; auth?: AuthCredentials; subdomain?: string | null; localtunnel?: Record; [key: string]: unknown; } /** * As the tunnel page is public the plugin will require basic auth. * * You can set your own credentials using `opts` or `setAuthCredentials()`. * * If you don't specify basic auth credentials the plugin will * generate a password and print it to STDOUT. * * **opts** * @param {Object} opts - Options * @param {Object} [opts.auth] - Basic auth credentials for the public page * @param {string} [opts.auth.user] - Username (default: 'user') * @param {string} [opts.auth.pass] - Password (will be generated if not provided) * @param {Object} [opts.prefix] - The prefix to use for the localtunnel.me subdomain (default: 'devtools-tunnel') * * @example * import puppeteer from '@zorilla/puppeteer-extra' * import devtoolsPlugin from '@zorilla/puppeteer-extra-plugin-devtools' * const devtools = devtoolsPlugin({ * auth: { user: 'francis', pass: 'president' } * }) * puppeteer.use(devtools) * * puppeteer.launch().then(async browser => { * console.log('tunnel url:', (await devtools.createTunnel(browser)).url) * // => tunnel url: https://devtools-tunnel-n9aogqwx3d.localtunnel.me * }) */ declare class Plugin extends PuppeteerExtraPlugin { private _browserSessions; constructor(opts?: PluginOptions); get name(): string; get defaults(): Partial; /** * Create a new public tunnel. * * Supports multiple browser instances (will create a new tunnel for each). * * @param {Puppeteer.Browser} browser - The browser to create the tunnel for (there can be multiple) * @return {Tunnel} The {@link Tunnel} instance * * @example * import puppeteer from '@zorilla/puppeteer-extra' * import devtoolsPlugin from '@zorilla/puppeteer-extra-plugin-devtools' * const devtools = devtoolsPlugin() * devtools.setAuthCredentials('bob', 'swordfish') * puppeteer.use(devtools) * * ;(async () => { * const browserFleet = await Promise.all( * [...Array(3)].map(slot => puppeteer.launch()) * ) * for (const [index, browser] of browserFleet.entries()) { * const {url} = await devtools.createTunnel(browser) * console.info(`Browser ${index}'s devtools frontend can be found at: ${url}`) * } * })() * // => * // Browser 0's devtools frontend can be found at: https://devtools-tunnel-fzenb4zuav.localtunnel.me * // Browser 1's devtools frontend can be found at: https://devtools-tunnel-qe2t5rghme.localtunnel.me * // Browser 2's devtools frontend can be found at: https://devtools-tunnel-pp83sdi4jo.localtunnel.me */ createTunnel(browser: Browser): Promise; /** * Set the basic auth credentials for the public tunnel page. * * Alternatively the credentials can be defined when instantiating the plugin. * * @param {string} user - Username * @param {string} pass - Password * * @example * import puppeteer from '@zorilla/puppeteer-extra' * import devtoolsPlugin from '@zorilla/puppeteer-extra-plugin-devtools' * const devtools = devtoolsPlugin() * puppeteer.use(devtools) * * puppeteer.launch().then(async browser => { * devtools.setAuthCredentials('bob', 'swordfish') * const tunnel = await devtools.createTunnel(browser) * }) */ setAuthCredentials(user: string, pass: string): this; /** * Convenience function to get the local devtools frontend URL. * * @param {Puppeteer.Browser} browser * @return {string} * * @example * import puppeteer from '@zorilla/puppeteer-extra' * import devtoolsPlugin from '@zorilla/puppeteer-extra-plugin-devtools' * const devtools = devtoolsPlugin() * puppeteer.use(devtools) * * puppeteer.launch().then(async browser => { * console.log(devtools.getLocalDevToolsUrl(browser)) * // => http://localhost:55952 * }) */ getLocalDevToolsUrl(browser: Browser): string; /** * Prints the generated auth credentials, when not overriden by the user. * * As the tunnel is public we make basic auth a requirement, * without forcing the user to specify their own credentials. * * @ignore */ _printGeneratedPasswordWhenNotOverridden(url: string): void; } /** * The devtools tunnel for a browser instance. * */ declare class Tunnel extends RemoteDevTools.DevToolsTunnel { constructor(wsEndpoint: string, opts?: PluginOptions); /** * Get the public devtools frontend url. * * @return {string} - url * * @example * const tunnel = await devtools.createTunnel(browser) * console.log(tunnel.url) * // => https://devtools-tunnel-sdoqqj95vg.localtunnel.me */ get url(): string; /** * Get the devtools frontend deep link for a specific page. * * @param {Puppeteer.Page} page * @return {string} - url * * @example * const page = await browser.newPage() * const tunnel = await devtools.createTunnel(browser) * console.log(tunnel.getUrlForPage(page)) * // => https://devtools-tunnel-bmkjg26zmr.localtunnel.me/devtools/inspector.html?ws(...) */ getUrlForPage(page: Page): string; /** * Close the tunnel. * * The tunnel will automatically stop when your script exits. * * @example * const tunnel = await devtools.createTunnel(browser) * tunnel.close() */ close(): this; } declare const _default: (pluginConfig?: PluginOptions) => Plugin; export default _default; //# sourceMappingURL=index.d.ts.map