fix(build): generate protocol in chromium (#1579)
This commit is contained in:
parent
a042466125
commit
6903496f2d
|
|
@ -9,13 +9,13 @@ const util = require('util');
|
||||||
async function generateChromiumProtocol(executablePath) {
|
async function generateChromiumProtocol(executablePath) {
|
||||||
const outputPath = path.join(__dirname, '..', '..', 'src', 'chromium', 'protocol.ts');
|
const outputPath = path.join(__dirname, '..', '..', 'src', 'chromium', 'protocol.ts');
|
||||||
const playwright = await require('../../index').chromium;
|
const playwright = await require('../../index').chromium;
|
||||||
const browserServer = await playwright.launchServer({ executablePath, args: ['--no-sandbox'] });
|
const args = playwright._defaultArgs();
|
||||||
const origin = browserServer.wsEndpoint().match(/ws:\/\/([0-9A-Za-z:\.]*)\//)[1];
|
args.push('--remote-debugging-port=9339');
|
||||||
const browser = await playwright.connect({ wsEndpoint: browserServer.wsEndpoint() });
|
const browser = await playwright.launch({ executablePath, args, ignoreDefaultArgs: true });
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto(`http://${origin}/json/protocol`);
|
await page.goto(`http://localhost:9339/json/protocol`);
|
||||||
const json = JSON.parse(await page.evaluate(() => document.documentElement.innerText));
|
const json = JSON.parse(await page.evaluate(() => document.documentElement.innerText));
|
||||||
await browserServer.close();
|
await browser.close();
|
||||||
await fs.promises.writeFile(outputPath, jsonToTS(json));
|
await fs.promises.writeFile(outputPath, jsonToTS(json));
|
||||||
console.log(`Wrote protocol.ts to ${path.relative(process.cwd(), outputPath)}`);
|
console.log(`Wrote protocol.ts to ${path.relative(process.cwd(), outputPath)}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue