Home > front end >  Changing document.title through JavaScript anonymous function
Changing document.title through JavaScript anonymous function

Time:12-25

I am still a bit new to JavaScript. I am trying to dynamically change the title of a page through javascript. However I am getting a result of undefined. I have tried multiple things and still no luck. What is the right way to pass a value to this anonymous function?

let email = "[email protected]"
await page.evaluate(  (email) => document.title = email );
console.log(await page.title());

CodePudding user response:

I never used playwright js, but reading this documentation page here, https://playwright.dev/docs/evaluating, it looks like you pass arguments for the anonymous function as the second, and next parameters, of the evaluation method:

let email = "[email protected]"
await page.evaluate( (email) => document.title = email, email );
console.log(await page.title());
  • Related