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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_navigate_listener #676

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dandeto
Copy link
Collaborator

@dandeto dandeto commented Feb 19, 2022

This is my first stab at creating several cross-platform event listeners! I do not have a Mac, so this only works on Linux GTK and Windows webview2. Hopefully this will inspire someone to port it to Mac.

The add_navigate_listener is a dead-simple function. When a new webpage has loaded, this listener calls whatever handler the user specified and passes it the current url. Here is an example:

void navigate_callback(const char* url) {
  std::cout << url << '\n';
  // any additional logic with the url here.
  // maybe if url is not https, navigate away.
}
...
// now pass the callback to the webview listener
w.add_navigate_listener(navigate_callback);

Feedback appreciated!

webview.h Outdated Show resolved Hide resolved
@justjosias
Copy link
Member

Is generic event listener code possible? I don't think we want to add individual event listeners for every possible event.

@dandeto
Copy link
Collaborator Author

dandeto commented Feb 26, 2022

That progress is being tracked over at #659. I think it is possible for mac and linux, but it looks very difficult for windows, especially with our current architecture. I was going to just add this navigate listener and a window destroy listener so that the app can show a confirm dialogue and cancel the window close if the user changes his mind. dandeto@e4ef6e3
I haven't felt strongly about other listeners being necessary yet, but if I do I'll make a new PR, of course!

I still think we should ideally add a completely generic way to create any listener. If that is not possible, we should expose the platform specific event system. I'm still working on it.

Bottom-line, a navigate event listener is 100% necessary for a webview library, whether or not we create a more robust event system.

@justjosias
Copy link
Member

Looking over this again, I agree that it should be added. But it needs to support macOS first. Help porting it would be much appreciated.

@dandeto dandeto linked an issue Jun 17, 2022 that may be closed by this pull request
akallabeth added a commit to akallabeth/webview that referenced this pull request Jun 21, 2023
inspired by webview#676
provide a callback in case of navigation completed with a custom
argument provided at registration time.
akallabeth added a commit to akallabeth/webview that referenced this pull request Aug 30, 2023
inspired by webview#676
provide a callback in case of navigation completed with a custom
argument provided at registration time.
akallabeth added a commit to akallabeth/webview that referenced this pull request Aug 30, 2023
inspired by webview#676
provide a callback in case of navigation completed with a custom
argument provided at registration time.
akallabeth added a commit to akallabeth/webview that referenced this pull request Aug 30, 2023
inspired by webview#676
provide a callback in case of navigation completed with a custom
argument provided at registration time.
akallabeth added a commit to akallabeth/webview that referenced this pull request Aug 30, 2023
inspired by webview#676
provide a callback in case of navigation completed with a custom
argument provided at registration time.
@SteffenL SteffenL added the type: feature Pull request is a feature label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Pull request is a feature
Development

Successfully merging this pull request may close these issues.

Web Event Callbacks?
4 participants