I've encountered a bug while trying to request an API that I've implemented. After using one of the endpoints, it throws the following error, as shown below.
Is there any way to handle this error?
Error message:
TypeError: Cannot read property 'contentFrame' of null
at Object.getAnimeVideo (C:\Users\c\Desktop\ryuanime\src\api\scraper.ts:89:37)
at process._tickCallback (internal/process/next_tick.js:68:7)
Code:
const getAnimeVideo = async (id: string, chapter: number) => {
const BASE_URL = `${url}${id}/${chapter}/`;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(BASE_URL);
const elementHandle = await page.$('.player_conte');
const frame = await elementHandle.contentFrame(); //line 89 error
const video = await frame.$eval('#jkvideo_html5_api', el =>
Array.from(el.getElementsByTagName('source')).map(e => e.getAttribute("src")));
await browser.close();
return video;
}