I have problems in returning the result of a promise to a variable. The only way that works for me is making a console.log, but it's not what I want.
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();
const video = await frame.$eval('#jkvideo_html5_api', el =>
Array.from(el.getElementsByTagName('source')).map(e => e.getAttribute("src")));
return video;
}
getAnimeVideo('tokyo-magnitude-80' , 1)
.then(res => console.log(res)); // It shows me the data correctly.
const T = getAnimeVideo('tokyo-magnitude-80' , 1)
.then(res => {
return res; //Promise { <pending> }
})