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

implement navigation callbacks #942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akallabeth
Copy link

inspired by #676
provide a callback in case of navigation completed with a custom argument provided at registration time.

(linux/windows/mac implemented)

@dandeto
Copy link
Collaborator

dandeto commented Aug 29, 2023

Nice work! I'm glad someone with Mac expertise swooped in. Could you please de-conflict webview.h and retest for an easier merge? Sorry it took so long to receive any comments on this.
I will test on Linux and Windows and provide any feedback I have. We will take your word on Mac, because I don't think anyone here has a Mac.

Copy link
Collaborator

@SteffenL SteffenL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it has taken so long to review this, and thanks @dandeto for getting started.

I'll pitch in because there is quite a bit to comment on here. I understand this is partially based on #676 but I'll comment on this PR independently.

Aside from the inline comments:

  • When do we get notified of navigation changes? Before, after, both?
  • Do we get notified for the navigation as one unit, or do we get notified for little every request in between?
  • Is the behavior consistent across all of the supported platforms?
  • Is there a reason why the feature is missing from the C interface?
  • Since a navigation handler is always added internally, how much could this impact performance when users don't need to be notified?
  • It would be great with some tests.

We will take your word on Mac, because I don't think anyone here has a Mac.

I can test this when we're more confident in merging the work.

webview.h Outdated Show resolved Hide resolved
webview.h Show resolved Hide resolved
webview.h Outdated Show resolved Hide resolved
webview.h Outdated Show resolved Hide resolved
webview.h Outdated Show resolved Hide resolved
webview.h Outdated Show resolved Hide resolved
class_addProtocol(cls, objc_getProtocol("WKNavigationDelegate"));
class_addMethod(cls, "webView:didFinishNavigation:"_sel,
(IMP)(+[](id delegate, SEL sel, id webview, id navigation) {
auto w = get_associated_webview(delegate);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be careful here with memory management given the potential frequency of the execution of this code. What does the memory footprint look like?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, not too familiar with the apple profiling frameworks.

Copy link
Collaborator

@SteffenL SteffenL Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this should give an idea about the memory consumption:

  • Record the app's memory usage after a single navigation.
  • Repeat navigation a bunch of times, whether with a local server (e.g. python3 -m http.server --bind 127.0.0.1 8000) or any other way that triggers the code to execute, and watch memory consumption. Not sure if it's enough to call navigate() or if we need to automate mouse/keyboard taps.
  • After the loop, see whether memory consumption goes down after a few seconds. It's pretty lazy.
  • If memory consumption goes down to normal levels then it should be fine.

If this looks OK then I would just skip profiling because we probably still have some other memory-related issues on macOS that aren't too severe.

webview.h Outdated Show resolved Hide resolved
w->m_navigateCallback(str, w->m_navigateCallbackArg);
}),
"v@:@");
objc_registerClassPair(cls);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fix is not required for this PR since the fixes in #1005 aren't merged yet, but I'll just leave a note: Will crash when attempting to register the same class a second time.

webview.h Outdated Show resolved Hide resolved
@akallabeth akallabeth force-pushed the navigation_callbacks branch 3 times, most recently from d8d136b to 1330997 Compare August 30, 2023 07:36
@akallabeth
Copy link
Author

akallabeth commented Aug 30, 2023 via email

inspired by webview#676
provide a callback in case of navigation completed with a custom
argument provided at registration time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants