Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM support #30

Open
olanod opened this issue Nov 14, 2020 · 5 comments
Open

WASM support #30

olanod opened this issue Nov 14, 2020 · 5 comments
Labels
question Further information is requested

Comments

@olanod
Copy link

olanod commented Nov 14, 2020

I haven't tried compiling this to WASM but I will assume it doesn't 馃槄
I might sound weird wanting to run a browser automation tool from a browser environment but I have a use case of a plug-in system where plugins are JS or Rust compiled to WASM running in a WebWorker, this plug-ins can run in the browser and the server with the help of Deno. The browser APIs limit me to use fetch or WebSocket based libraries so I was looking for Webdriver rust libraries that would use reqwest as HTTP client which supports compiling to browser WASM, I used fantoccini a bit and was planning to work on a fork that used reqwest but I'm glad to see Thirtyfour exists and the API might even be nicer.

@stevepryde
Copy link
Owner

Honestly I haven't tried compiling to WASM either.
One thing I want to point out is that this library (and likewise fantoccini and other selenium/webdriver libraries) doesn't actually do any browser automation itself. Instead it issues HTTP requests/commands to a webdriver server (chromedriver/geckodriver etc) and it is the webdriver that actually takes care of launching another browser instance and interacting with it. Does that sound like what you're trying to do?

I'm wondering if it isn't easier to simply use javascript/WASM to control the browser you're currently running in, instead.

I guess that's where I'm still a little confused by what you're trying to do. To clarify, are you wanting to do web requests from a browser, to a local webdriver server (or I guess it could be remote if you wish), to then control a separate browser instance?

@olanod
Copy link
Author

olanod commented Nov 15, 2020

You got it right ;)
I'm aware the webdriver server does the magic and the library is just a client. About the WASM/JS code controlling the current browser, unless I'm missing something one does not "just" control the current browser right? And for some of the stuff that I need to run(e.g. make a screen capture) it won't work to just let the Rust WASM code do things with the current document because this WASM plugin not only doesn't have DOM access(runs in a worker) but also doesn't know if it will be running in a browser or a server. Does it make sense? 馃槄
Anyway if I have time later enxt week I'll test the WASM compilation, doesn't seem that difficult maybe some parts of the code would need to be feature gated if they are doing things like accessing the file system.

@stevepryde
Copy link
Owner

Ok yes that makes sense. Let me know how the WASM compilation goes

@stevepryde stevepryde added the question Further information is requested label Dec 8, 2020
@TilBlechschmidt
Copy link
Contributor

@olanod you probably have to create a new HTTP request backend. The current default is reqwest which most likely will not even compile to WASM. However, wasm-bindgen or rather js-sys provides access to the native JavaScript APIs for making HTTP requests so it should not be too hard to work around it that way. AFAIK the HTTP client is already abstracted away in thirtyfour 馃檪

@stevepryde
Copy link
Owner

Yes the http client is abstracted out and you can implement the relevant trait and supply your own.

I'm keen to see how far you get with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants