#Puppeteer in gleam
1 messages · Page 1 of 1 (latest)
You can make an ffi module exposing the Puppeteer API you need and call those functions from your Gleam modules.
my time to shine
A browser automation tool and interface to the Chrome DevTools Protocol.
@spring panther I can't find a way to run selector scoped by element.
https://hexdocs.pm/chrobot/chrobot.html#select_all accepts only page
There is https://hexdocs.pm/chrobot/protocol/dom.html#query_selector
but it looks like not intended to be used from consumer code and most like exists for internal purposes.
@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
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.
Alright here it is @sturdy kestrel
https://hexdocs.pm/chrobot/chrobot.html#select_from
https://hexdocs.pm/chrobot/chrobot.html#select_all_from
on 2.3.0
let me know if there's any issues with this 🙂