I have been playing around with Puppeteer settings and it seems that this error is not present when I set
puppeteer.launch({ headless:false });
The fetching only fails when I set headless: true
which is ideally what I want.
Error:
Logging into user...
Logged in!
Fetching username...
TypeError: Cannot read properties of undefined (reading 'getProperty')
at D:\boody\Programming\blxscrape\src\index.ts:40:27
at Generator.next (<anonymous>)
at fulfilled (D:\boody\Programming\blxscrape\src\index.ts:5:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Snippet of the code:
// username
await console.log('Fetching username...');
const [el]: any = await page.$x('/html/body/div[3]/main/div[2]/div[2]/div/div[1]/div/div[2]/div[2]/div[1]/div[2]');
let txt: any = await el.getProperty('textContent');
const usernameTxt: string = await txt.jsonValue();
// desc
await console.log('Fetching description...');
const [el2]: any = await page.$x('/html/body/div[3]/main/div[2]/div[2]/div/div[3]/div/div[1]/div[1]/div[2]/div/pre/span');
const descTxt: string = await page.evaluate((el2: any) => el2.textContent, el2);
// profile picture
await console.log('Fetching profile picture...');
const [el3]: any = await page.$x('/html/body/div[3]/main/div[2]/div[2]/div/div[1]/div/div[2]/div[1]/span/thumbnail-2d/span/img');
const src: any = await el3.getProperty('src');
const pfpUrl: string = await src.jsonValue();
const data: object = {usernameTxt, descTxt, pfpUrl};
console.log(data);
browser.close();
}
scrape('https://www.roblox.com/users/64004875/profile', process.env.USER, process.env.PASS);