mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
41 lines
974 B
JavaScript
41 lines
974 B
JavaScript
import puppeteer from 'puppeteer';
|
|
import path from 'path';
|
|
|
|
const pathToExtension = path.join(
|
|
process.cwd(),
|
|
'puppeteer-in-extension',
|
|
'out'
|
|
);
|
|
|
|
const browser = await puppeteer.launch({
|
|
headless: true,
|
|
args: [
|
|
`--disable-extensions-except=${pathToExtension}`,
|
|
`--load-extension=${pathToExtension}`,
|
|
'--silent-debugger-extension-api',
|
|
],
|
|
});
|
|
|
|
try {
|
|
const port = process.argv[2];
|
|
|
|
const workerTarget = await browser.waitForTarget(
|
|
target =>
|
|
target.type() === 'service_worker' &&
|
|
target.url().endsWith('background.js')
|
|
);
|
|
const worker = await workerTarget.worker();
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
const result = await worker.evaluate(async url => {
|
|
return await globalThis.testConnect(url);
|
|
}, `http://localhost:${port}/playground.html`);
|
|
|
|
if (result !== 'Playground') {
|
|
throw new Error('Unexpected playground.html page title: ' + result);
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|