-
Notifications
You must be signed in to change notification settings - Fork 81
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does Page.expose_function work? #223
Comments
rust-headless-chrome's expose_function implementation seems to do more what it is supposed to do: |
This does not seem to print anything either... let (browser, mut handler) = Browser::launch(browser_config)
.await
.expect("Failed to launch browser");
// Spawn a task to handle browser events
tokio::spawn(async move {
while let Some(event) = handler.next().await {
println!("Event: {:?}", event);
}
});
page.execute(AddBindingParams::new("MTMTMT1")).await.expect("Failed to add binding");
let mut event_listener: EventStream<EventBindingCalled> = browser.event_listener().await.expect("Failed to get event listener");
tokio::spawn(async move {
while let Some(event) = event_listener.next().await {
println!("Event 2: {:?}", event);
}
}); The MTMTMT1 is shown in the client side side but calling it does not print anything in rust backend ... there has to be some way |
After going through the source code I figured out how this is done. I opened a PR for new example to possibly help others with similar issue. #224 |
Achieving this functionality is possible by using |
Hi,
Can somebody provide example or more info how
Page.expose_function
is supposed to be used?chromiumoxide/src/page.rs
Lines 272 to 290 in 0897fb5
I got it to compile used like this:
and it seems to get registered client side:
But that does not fulfill the purpose why expose_function exists, the idea is to expose a method so client side JS could call the Rust backend as shown here: https://pptr.dev/api/puppeteer.page.exposefunction.
Am I missing something here or is this functionality broken?
The text was updated successfully, but these errors were encountered: