How do you access `document` on Node?
Urigo opened this issue · 6 comments
For example
let listLength = await page.evaluate((sel) => {
return document.getElementsByClassName(sel).length;
}, LENGTH_SELECTOR_CLASS);
Where does document
comes from?
I don't want to import implicitly but only explicitly...
Thanks!
Actually the code inside the callback passed to evaluate
is executed in Browser's Context. What that means is, it's like your JavaScript code inside <script>
tags in a html page. Or for that matter, inside the html page where you've navigated to, using puppeteer
.
So, you have probably access to other global DOM objects like window
, location
as well.
(Though I haven't tried these)
BTW @Urigo I am a fan of your work on Angular Meteor. I have also worked with your guide on Whatsapp with Ionic & Meteor :)
@emadehsan thank you :) I hope to release some cool new stuff soon :)
and thank you for your answer!
I wonder how can I satisfy the Typescript compiler with this context, maybe the evaluate
function returns the Browser's context? maybe I'll just assert to the Typescript compiler to ignore this
@Urigo this pull request when merged might fulfill your requirements
thanks again @emadehsan !
Any time!