Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Pass multiple arguments to Page.evaluate()

I have the below Playwright-TS code. I am passing email id dynamically to the tester method and I want it inside page.evaluate but email:emailId in the below code errors out as undefined.

  apiData = {
    name: faker.name.firstName(),
    domain: process.env['DOMAIN'],
  };
async tester(page: Page, emailId: string)
    {
      await page.evaluate((apiData) =>
      { 
          const authentication = {
          userId: window.localStorage.getItem('userId')
        };

        const data = 
        {
            email:emailId
        };

        fetch(`${apiData.domain}/api/v1/user`, 
        {
          method: 'POST',
          headers: {
          'content-type': 'application/json',
           cookie: authentication.allCookies,
          },
          body: JSON.stringify(data),
          })
          .then(response => response.json())
          .then(myJson => {
          newUserId = JSON.stringify(myJson.data.id).replace(/\"/g, "");
            
      },this.apiData);
    }

I tried passing it as:

await page.evaluate(([apiData, emailReceived] =>
   { 
    },[this.apiData, emailId]);

But then apiData values throws error - Property 'domain' does not exist on type 'string'.

I tried other solutions but none seems to work for me. How can I implement this?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You can add the emailId to the apiData:

await page.evaluate(([apiData, emailReceived] =>
  { 
  },
  {
   ...this.apiData, 
   emailId
  });

And then you will be able to use apiData.emailId inside the function you are evaluating.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda