Node js pass parameter to function

I have this code :

const { Logger } = require ("telegram/extensions");
const { TelegramClient } = require ("telegram");
const { StringSession } = require ("telegram/sessions");
const { NewMessage } = require ("telegram/events");
const { NewMessageEvent } = require ("telegram/events/NewMessage");
const { Message } = require ("telegram/tl/custom/message");
const input = require('input'); // npm i input
const puppeteer = require('puppeteer-extra');


async function eventHandler(event, browser, test) {
    
    const page = await event.browser.newPage();

}


const client = new TelegramClient(
  new StringSession(stringSession),
  apiId,
  apiHash,
  { connectionRetries: 5 }
);


(async () => {
  console.log('Loading interactive example...')
  const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--shm-size=2gb', '--start-maximized', '--disable-features=IsolateOrigins,site-per-process', '--disable-web-security'], headless: true});
  await client.start({
      phoneNumber: "+33...",
      password: async () => await input.text('password?'),
      phoneCode: async () => await input.text('Code ?'),
      onError: (err) => console.log(err),
  });
  console.log('Telegram bot connected');
  console.log(client.session.save());
  client.addEventHandler(eventHandler, new NewMessage({}), browser);

})();

I want to pass the browser variable to the eventHandler function.
I try like that, but it does not work, browser came "undefined" in eventHandler.

How pass the browser variable to my eventHandler?

Source: Ask Javascript Questions

LEAVE A COMMENT