nodejs我想在闭包中动态执行调试代码,上下文是在闭包中,而不是上下文中,如何实现?-灵析社区

周舟莫UI设计

pt.launch({ // slowMo: 250, devtools: true, headless: false, // executablePath: '/path/to/Chrome', args: [ '--disable-features=site-per-process', '--disable-notifications=true' ], ignoreDefaultArgs: ['--enable-automation'], // devtools: false, }).then(async browser => { const page = await browser.newPage() 在这里打断点动态执行

阅读量:240

点赞量:9

问AI
const puppeteer = require('puppeteer'); const readline = require('readline'); (async () => { const browser = await puppeteer.launch({ devtools: true, headless: false, }); const page = await browser.newPage(); await page.goto('https://example.com'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on('line', async (input) => { try { if (input === 'exit') { await browser.close(); rl.close(); } else { console.log(`Executing: ${input}`); const result = await eval(`page.${input}`); console.log('Result:', result); } } catch (error) { console.error('Error executing command:', error); } }); })(); rl.on('line', async (input) => { try { if (input === 'exit') { await browser.close(); rl.close(); } else { console.log(`Executing: ${input}`); const result = await eval(`(async () => { return await page.${input} })()`); console.log('Result:', result); } } catch (error) { console.error('Error executing command:', error); } });