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

Support BrowserComponent.setDebugMode on iOS #3868

Open
Rocketeer007 opened this issue Jan 31, 2025 · 3 comments
Open

Support BrowserComponent.setDebugMode on iOS #3868

Rocketeer007 opened this issue Jan 31, 2025 · 3 comments
Assignees

Comments

@Rocketeer007
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When working with a BrowserComponent, it is a lot easier to understand what's going on if you are able to use Safari to debug JavaScript inside the WKWebView. Currently, this is not supported without manually editing generated iOS native code.

Describe the solution you'd like
Calling BrowserComponent.setDebugMode(true) should, ideally, result in a call to wkWebView.inspectable = YES;, and disabling this should set it back to NO.

Describe alternatives you've considered
Manually editing the iOS native code works:

Subject: [PATCH] Make WKWebView inspectable
---
Index: Ports/iOSPort/nativeSources/IOSNative.m
<+>UTF-8
===================================================================
diff --git a/Ports/iOSPort/nativeSources/IOSNative.m b/Ports/iOSPort/nativeSources/IOSNative.m
--- a/Ports/iOSPort/nativeSources/IOSNative.m	(revision 329216c760660a63198c26b0e87224476cfa2760)
+++ b/Ports/iOSPort/nativeSources/IOSNative.m	(date 1738323512897)
@@ -2489,6 +2489,7 @@
             com_codename1_impl_ios_IOSNative_createWKBrowserComponent.backgroundColor = [UIColor clearColor];
             com_codename1_impl_ios_IOSNative_createWKBrowserComponent.opaque = NO;
             com_codename1_impl_ios_IOSNative_createWKBrowserComponent.autoresizesSubviews = YES;
+            com_codename1_impl_ios_IOSNative_createWKBrowserComponent.inspectable = YES;
             
             com_codename1_impl_ios_IOSNative_createWKBrowserComponent.navigationDelegate = del;
             com_codename1_impl_ios_IOSNative_createWKBrowserComponent.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

We could also consider adding a build hint that would turn this on or off for an entire project.

Additional context
Reddit discussion: https://www.reddit.com/r/cn1/comments/1idt7ez/webbrowser_javascript_interoperability_debugging/

@shai-almog
Copy link
Collaborator

@shannah it seems that having a setBrowserProperty would be the right way to expose this for iOS. Right?
Maybe something generic like the stuff you did on Android?

@shannah
Copy link
Collaborator

shannah commented Feb 1, 2025

Thanks @Rocketeer007 . I have created a PR based on this. Tested on my sample app and works.

#3869

You need to call setDebug(true) on the browser component to enable it.
Should have this in for next week's release.

@Rocketeer007
Copy link
Contributor Author

I've had a look at the change, and I believe that it works in your test case - but I have a feeling that calling setDebugMode(false) later would have no impact, and calling setDebugMode(true) after the browser component has already been displayed would likewise have no impact.

I vaguely expected an implementation that would make use of Display.impl.setBrowserProperty, check for the property being "debug mode" or something similar, then call a new method along the lines of nativeInstance.setBrowserInspectable(PeerComponent browserPeer, Boolean value)

I'm away from my computer this weekend... but I'd be happy to put together a PR showing this implementation on Monday if you'd like.

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

No branches or pull requests

3 participants