Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing document.title through JavaScript anonymous function

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 = "myemail@email.com"
await page.evaluate(  (email) => document.title = email );
console.log(await page.title());

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 = "myemail@email.com"
await page.evaluate( (email) => document.title = email, email );
console.log(await page.title());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading