47 lines
1.8 KiB
JavaScript
47 lines
1.8 KiB
JavaScript
// Smoke test to try connecting to browserless via Puppeteer
|
|
// Tries common WS endpoints and navigates to the local app to validate connectivity.
|
|
const puppeteer = require('puppeteer-core');
|
|
|
|
const TOKEN = 'e2e098863b912f6a178b68e71ec3c58d';
|
|
const HOST = process.env.HOST_IP || '192.168.1.19';
|
|
const PORT = process.env.HOST_PORT || '5173';
|
|
const BASE_URL = process.env.BASE_URL || `http://${HOST}:${PORT}`;
|
|
|
|
const endpoints = [
|
|
`wss://browserless.bfzqqk.easypanel.host/puppeteer?token=${TOKEN}`,
|
|
`wss://browserless.bfzqqk.easypanel.host/?token=${TOKEN}`,
|
|
`wss://browserless.bfzqqk.easypanel.host/devtools?token=${TOKEN}`,
|
|
// try without path
|
|
`wss://browserless.bfzqqk.easypanel.host/playwright?token=${TOKEN}`,
|
|
];
|
|
|
|
(async () => {
|
|
console.log('BASE_URL =', BASE_URL);
|
|
for (const ep of endpoints) {
|
|
console.log('\nTrying endpoint:', ep);
|
|
try {
|
|
const browser = await puppeteer.connect({
|
|
browserWSEndpoint: ep,
|
|
defaultViewport: null,
|
|
// some providers require a slowMo or ignoreHTTPSErrors
|
|
ignoreHTTPSErrors: true,
|
|
timeout: 15000,
|
|
});
|
|
const page = await browser.newPage();
|
|
console.log('Connected to browserless, navigating to', BASE_URL);
|
|
await page.goto(BASE_URL, { waitUntil: 'load', timeout: 20000 }).catch(e => { throw e; });
|
|
const title = await page.title().catch(() => 'no-title');
|
|
const contentLen = await page.content().then(c => c.length).catch(() => 0);
|
|
console.log('Navigation OK. title=', title, 'content length=', contentLen);
|
|
await browser.close();
|
|
console.log('SUCCESS endpoint:', ep);
|
|
process.exit(0);
|
|
} catch (err) {
|
|
console.error('Endpoint failed:', ep, '\n', err && err.message ? err.message : err);
|
|
// continue to next
|
|
}
|
|
}
|
|
console.error('\nAll endpoints failed. See errors above.');
|
|
process.exit(2);
|
|
})();
|