#Puppeteer in gleam

1 messages · Page 1 of 1 (latest)

pearl depot
#

is there anyway to use puppeteer (or something similar like playwright) inside gleam? Or should I just expose what I need through a REST API on an external service?

winter nebula
#

You can make an ffi module exposing the Puppeteer API you need and call those functions from your Gleam modules.

spring panther
#

my time to shine

sturdy kestrel
spring panther
#

@sturdy kestrel Yeah I think that's probably pretty confusing, but don't use the DOM domain to interact with the DOM for automation, I wrote a note about this (and the reason) here https://hexdocs.pm/chrobot/protocol.html – maybe I should just remove that domain altogether though, but, it's just how the Chrome Devtools Protocol is and for now I have 1:1 bindings to the protocol as part of the package.

Basically all DOM automation in chrobot happens via the Runtime domain, so literally just injecting JavaScript to call the respective functions and parsing the result.

You're right, it looks like I have not implemented a helper to call a selector on an element, I think this could be useful, I'll make an issue for it 🙂
It'll be pretty simple though, for calling functions on Elements I have the chrobot.call_custom_function_on helper, you can see how it's used here for example to achieve something similar:
https://github.com/JonasGruenwald/chrobot/blob/v2.2.5/src/chrobot.gleam#L382-L386

sturdy kestrel
#

I can't find suitable decoder for call_custom_function_on for my use case

spring panther
# sturdy kestrel I can't find suitable decoder for `call_custom_function_on` for my use case

yeah I forgot how that works, these are hardcoded to return by value, and you probably don't want a value, you want the remote object.

I started to work on this here just now:
https://github.com/JonasGruenwald/chrobot/compare/main...element_query_selectors#diff-f69971d861dfa20ecc215a79f5aa89a43938462d1a989aeac1e463c7c5ce5eaaR663
this is working for the single query selector, still would have to make a version of querySelectorAll that works on elements as well.

#

I do think it's probably not the best to do a lot of juggling of remote object references in Gleam, if I need this sort of nested filtering and selection personally I would just write a couple lines of js that return a serializable value and stick it in a single eval call, should also be faster that way.

spring panther