Files
manybot/node_modules/whatsapp-web.js/src/util/Puppeteer.js
2026-03-12 01:22:29 -03:00

24 lines
626 B
JavaScript

/**
* Expose a function to the page if it does not exist
*
* NOTE:
* Rewrite it to 'upsertFunction' after updating Puppeteer to 20.6 or higher
* using page.removeExposedFunction
* https://pptr.dev/api/puppeteer.page.removeexposedfunction
*
* @param {object} page - Puppeteer Page instance
* @param {string} name
* @param {Function} fn
*/
async function exposeFunctionIfAbsent(page, name, fn) {
const exist = await page.evaluate((name) => {
return !!window[name];
}, name);
if (exist) {
return;
}
await page.exposeFunction(name, fn);
}
module.exports = {exposeFunctionIfAbsent};