Node.js “木偶演员阻止”;暂停调试“;禁用所有断点

Node.js “木偶演员阻止”;暂停调试“;禁用所有断点,node.js,google-chrome,puppeteer,Node.js,Google Chrome,Puppeteer,我需要一个有很多调试器的无头模式的网站 有没有一种方法可以防止调试器暂停 我试图发送加载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'); 有什么建议吗?木偶演员会自动按下页面中的键,而不是浏览器中的

我需要一个有很多
调试器的无头模式的网站

有没有一种方法可以防止调试器暂停

我试图发送加载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');

有什么建议吗?

木偶演员会自动按下
页面中的键,而不是浏览器中的键

因此,我认为解决方案是安装一个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,它是否有效,请尝试以下代码

下面的代码运行puppeter并使用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())
})()
const puppeter=require('puppeter')
const robot=require('robotjs')
constpageurl=https://www.google.com'
常量正常字符串=[''''、'1'、'2'、'3'、'4'、'5'、'6'、'7'、'8'、'9'、'0'、'-'、'='、'['、']'、'\'、'\'、';'、'\'、'\'、'、'''/']
常量移位字符串=['~'、'!'、'@'、'#'、'$'、'%'、'^'、'&'、'*'、'('、')'、'''+'、'{'、'}'、'.'、':'、'''、''.'、'?']
;(异步()=>{
const browser=wait puppeter.launch({
无头:错,
devtools:对
})
const[page]=wait browser.pages()
const open=wait page.goto('https://www.example.com“,{waitUntil:'networkidle0',超时:0})
console.log('第一个URL:')
console.log(等待page.url())
等待robot.keytock('l','down','control')//对于Mac,将'control'更改为'command'
等待页面。等待(500)
等待robot.keytoking('l','up','control')//对于Mac,将'control'更改为'command'
等待页面。等待(1000)
for(让num进入pageURL){
if(shiftedStrings.includes(pageURL[num])){
var key=normal_Strings[shiftedStrings.indexOf(pageURL[num])]
等待机器人。按键开关(按键、‘向下’、‘移位’)
等待页面。等待(300)
等待机器人。按键开关(按键“向上”、“移位”)
等待页面。等待(300)
}
等待robot.keyTap(pageURL[num])
等待页面。等待(200)
}
等待页面。等待(1000)
等待机器人。按键('enter')
wait page.waitForSelector('img#hplogo[alt=“Google”]”,{timeout:0})
console.log('第二个URL:')
console.log(等待page.url())
})()

当然可以,我很乐意。如果您发现此代码运行良好,请不要忘记选择我的答案作为正确答案。抱歉,但不起作用…我已在Headles and normal中进行了尝试…控制台中显示了哪些错误(如果有)?它在我的Mac中运行良好。您是否已将
'command'
更改为
'control'
?是否已按类型安装
robotjs
软件包:
npm i robotjs
?控制台中没有错误,只是不按CTRL+F8禁用所有断点。我已将命令替换为control,并尝试更改按钮顺序。。。我认为问题在于,开发工具是“客户端”而不是服务器端,因此,您不能从bot禁用断点。如果您在
headless:true
模式下运行Puppeter,那么这个脚本将不会帮助您。我已经编写了一个脚本,用于调试它是否有效;这个脚本只通过在地址栏中键入URL来更改URL。