Chrome puppet 防止“暂停调试”又名禁用所有断点

k3bvogb1  于 2023-08-01  发布在  Go
关注(0)|答案(2)|浏览(194)

我需要用无头模式刮一个网站有很多debugger;
有办法防止调试器暂停吗?
我尝试发送加载CTRL+F8和F8与此代码,但没有成功!

await crt_page.keyboard.down('Control');
await crt_page.keyboard.press('F8');
await crt_page.keyboard.up('Control');
await crt_page.keyboard.press('F8');

字符串
有什么建议吗?

eoxn13cs

eoxn13cs1#

Puppeteer会自动按下page内部的键,而不是浏览器。
所以我认为解决方案是安装一个npm包robotjs来做浏览器之外的事情。
希望这对你有帮助!
如果这段代码有效的话,别忘了选择我的答案作为正确答案。

const puppeteer = require('puppeteer')
const robot = require('robotjs')

;(async () => {
    const browser = await puppeteer.launch({
        headless: false,
        devtools: true
    })
    const [page] = await browser.pages()

    const open = await page.goto('https://www.example.com', { waitUntil: 'networkidle0', timeout: 0 })

    await page.waitFor(4000)
    await robot.keyToggle(']','down','control') // For Mac, change 'control' to 'command'

    await page.waitFor(500)
    await robot.keyToggle(']','down','control') // For Mac, change 'control' to 'command'

    await page.waitFor(500)
    await robot.keyToggle(']', 'up', 'control') // For Mac, change 'control' to 'command'

    await page.waitFor(1000)
    await robot.keyToggle('f8','down','control') // For Mac, change 'control' to 'command'

    await page.waitFor(500)
    await robot.keyToggle('f8', 'up', 'control') // For Mac, change 'control' to 'command'

})()

字符串
要调试你的robotjs,它是否工作,请尝试此代码。
下面的代码运行puppeteer并使用robotjs更改URL。
如果这也不能在您的服务器上工作,那么很抱歉我不能帮助你。

const puppeteer = require('puppeteer')
const robot = require('robotjs')
const pageURL = 'https://www.google.com'
const normal_Strings = ['`','1','2','3','4','5','6','7','8','9','0','-','=','[',']','\\',';','\'',',','.','/']
const shiftedStrings = ['~','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?']

;(async () => {
    const browser = await puppeteer.launch({
        headless: false,
        devtools: true
    })
    const [page] = await browser.pages()

    const open = await page.goto('https://www.example.com', { waitUntil: 'networkidle0', timeout: 0 })

    console.log('First URL:')
    console.log(await page.url())
    await robot.keyToggle('l','down','control') // For Mac, change 'control' to 'command'
    await page.waitFor(500)
    await robot.keyToggle('l', 'up', 'control') // For Mac, change 'control' to 'command'
    await page.waitFor(1000)
    for (let num in pageURL) {
        if (shiftedStrings.includes(pageURL[num])) {
            var key = normal_Strings[ shiftedStrings.indexOf(pageURL[num]) ]

            await robot.keyToggle( key,'down','shift')
            await page.waitFor(300)
            await robot.keyToggle( key, 'up', 'shift')
            await page.waitFor(300)
        }
        await robot.keyTap(pageURL[num])
        await page.waitFor(200)
    }
    await page.waitFor(1000)
    await robot.keyTap('enter')

    await page.waitForSelector('img#hplogo[alt="Google"]', {timeout: 0})
    console.log('Second URL:')
    console.log(await page.url())
})()

ipakzgxi

ipakzgxi2#

我在抓取一些js中包含debug语句的页面时遇到了一些困难。
我刚把开发工具改成了false。开发工具窗格不在那里,调试语句不会导致问题。

const browser = await puppeteer.launch({
  headless: true,
  devtools: false,
  slowMo: 100
});

字符串

相关问题