I am getting the error TypeError: page._client.send is not a function when running the following code:
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: library_path, eventsEnabled: true});
Full code:
function downloadEQData() {
return new Promise(async function (resolve, reject) {
try {
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: global_headless });
const page = await browser.newPage();
// firt we navigate to the page and wait for it to load
var wait = page.waitForNavigation({ waitUntil: 'networkidle0' });
await page.goto('https://vendor.equator.com/index.cfm');
await wait;
console.log('At FNMA EQ Page');
// then we log in
await page.type('#enter_username', global_variables.username);
await page.type('#enter_password', global_variables.password);
var wait = page.waitForNavigation({ waitUntil: 'networkidle0' });
await page.click('button[type="submit"]');
await wait;
console.log('Logged In');
await sleep(6000);
// hover over workflow
await page.hover('#menubar > ul > li:nth-child(3)');
await sleep(1000);
// click search workflow
await page.click('#menubar > ul > li:nth-child(3) > ul > li:nth-child(4) > a')
await sleep(1000);
// select saved search "2Open Initial Services Wint", id:5126 (comes from the html code)
await page.select('#selSavedSearch', "5162");
await sleep(5000);
// click load search
await page.click('#btnLoadSearch')
await sleep(5000);
// click search
await page.click('#btnTaskSearch')
await sleep(5000);
// allowing download and setting the path to download to
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: library_path, eventsEnabled: true});
// this montiors download responses and returns the file name that was just downloaded as fileLink so that we can rename it later
page.on('response', response => {
//check for "Content-Disposition"
const disposition = response.headers()['content-disposition'];
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1]) {
fileLink = matches[1].replace(/['"]/g, '');
}
}
});
// the selector for the download link changes name so we are searching for the an id that starts with eqDataTabe and contains _excelBtn to clink on
await page.click('[id^="eqDataTable"][id*="_excelBtn"]');
console.log('Download Complete')
await sleep(5000);
// print out the file name just downloaded
console.log(fileLink)
// renaming the file to deliverables.xls
var file_name ='open_initials_deliverables.xls';
fs.rename(library_path+"/"+fileLink, library_path+"/"+file_name, (err) => {
if (err) throw err;
console.log('Rename complete!')})
// select saved search "Completed Initial Services Search", id:3426 (comes from the html code)
await page.select('#selSavedSearch', "3426");
await sleep(5000);
// click load search
await page.click('#btnLoadSearch')
await sleep(5000);
// input date
await page.evaluate((sel,date) => {
var el = document.querySelector(sel);
el.value = date;
}, '#state_date', date)
await sleep(5000);
// click search
await page.click('#btnTaskSearch')
await sleep(5000);
// the selector for the download link changes name so we are searching for the an id that starts with eqDataTabe and contains _excelBtn to clink on
await page.click('[id^="eqDataTable"][id*="_excelBtn"]');
console.log('Download Complete')
await sleep(5000);
// print out the file name just downloaded
console.log(fileLink)
// renaming the file to deliverables.xls
var file_name ='completed_initials_deliverables.xls';
fs.rename(library_path+"/"+fileLink, library_path+"/"+file_name, (err) => {
if (err) throw err;
console.log('Rename complete!')})
await page.close();
return resolve();
} catch ($e) {
console.log('ERROR:' + $e);
return reject();
}
});
}
Doing some research I thought it might be an issue with my program versions, but as you can see in the attached image everything seems to be up to date.
ERROR:TypeError: page._client.send is not a function
undefined
PS C:\Users\JakeYuraszeck\Desktop\AsseroServicesLLC\Scrapers\EQ Scrapers> node -v
v18.16.0
PS C:\Users\JakeYuraszeck\Desktop\AsseroServicesLLC\Scrapers\EQ Scrapers> npm -v
9.5.1
PS C:\Users\JakeYuraszeck\Desktop\AsseroServicesLLC\Scrapers\EQ Scrapers> npm list
eq-scrapers@1.0.0 C:\Users\JakeYuraszeck\Desktop\AsseroServicesLLC\Scrapers\EQ Scrapers
├── puppeteer-core@19.10.1
└── puppeteer@19.10.1
I would really appreciate being pushed in the right direction. Thanks.