Estoy intentando con este código obtener el cuerpo de respuesta de un sitio web usando titiritero
#!/usr/bin/env node require('dotenv').config(); const puppeteer = require('puppeteer'); const readline = require('readline').createInterface({ input: process.stdin, output: process.stdout }); const path = require('path'); const fs = require('fs'); // console.log('Starting Puppeteer...'); let responseBody = []; (async () => { const browser = await puppeteer.launch({ headless: false, executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' }); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { request.continue(); }); // page.on('requestfinished', async (request) => { const response = await request.response(); const url = response.url(); // store chunks url if( url.startsWith('https://audio-akp-quic-control-examplecdn-com.akamaized.net/audio/') ){ console.log(await response.buffer()); //responseBody.push(response.buffer()); } }); // await page.goto('https://accounts.examplecdn.com/login', { waitUntil: ['load', 'networkidle2'] }); const emailField = await page.waitForSelector('#login-username', {timeout: 3000}); await emailField.type(process.env.EMAIL, {delay: 100}); const passwordField = await page.waitForSelector('#login-password', {timeout: 3000}); await passwordField.type(process.env.PASSWORD, {delay: 100}); const submitButton = await page.waitForSelector('#login-button', {timeout: 3000}); await submitButton.click(); // const navigation = await page.waitForNavigation({ waitUntil: ['load', 'networkidle2'] }); //if( navigation.url().endsWith('status') ){ await page.goto('https://example.cdn.com/search', { waitUntil: ['load', 'networkidle2'] }).then( async (response) => { //console.log(response); const cookieButton = await page.$('#onetrust-accept-btn-handler'); await cookieButton.click(); const searchField = await page.$('[data-testid="search-input"]'); await readline.question('What track do you want to search for?', (input) => { console.log('answer:', input); searchField.type(input).then( async () => { await page.waitForXPath('//*[@id="searchPage"]/div/div/section[1]/div[2]/div/div/div/div[4]').then( async (element) => { element.focus().then( async () => { // //*[@id="searchPage"]/div/div/section[1]/div[2]/div/div/div/div[3]/button const playButton = await page.waitForXPath('//*[@id="searchPage"]/div/div/section[1]/div[2]/div/div/div/div[3]/button'); await playButton.click(); }); }); }); }); }); //} })();Tengo un problema con él y este error se registrará y el script terminará.
/Users/dev/Desktop/test/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208 this._callbacks.set(id, { resolve, reject, error: new Error(), method }); ^ Error: Protocol error (Network.getResponseBody): No resource with given identifier found at /Users/dev/Desktop/test/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208:63 at new Promise (<anonymous>) at CDPSession.send (/Users/dev/Desktop/test/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:207:16) at /Users/dev/Desktop/test/node_modules/puppeteer/lib/cjs/puppeteer/common/HTTPResponse.js:99:53 at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:93:5) at async /Users/dev/Desktop/test/index.js:40:25lo que debo hacer es recopilar todo el contenido del cuerpo de la respuesta cuando se llama a una determinada URL, luego, usando ffmpeg, quiero convertirlo nuevamente en una pista completa. ¿Cómo puedo resolver el problema? ¿Es posible obtener el cuerpo de respuesta de cada solicitud y luego unirlas todas?