Skip to content

Conversation

@shannah
Copy link
Collaborator

@shannah shannah commented Feb 1, 2025

Adds support for making iOS webview debuggable in safari. #3868

Use the setDebug(true) method on the webview.

package ca.weblite.jcbtest;

import static com.codename1.ui.CN.*;
import com.codename1.system.Lifecycle;
import com.codename1.ui.*;
import com.codename1.ui.layouts.*;
import com.codename1.io.*;
import com.codename1.ui.plaf.*;
import com.codename1.ui.util.Resources;

/**
 * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose
 * of building native mobile applications using Java.
 */
public class JSCallbackTest extends Lifecycle {
    @Override
    public void runApp() {
        Form hi = new Form("Browser", new BorderLayout());
        BrowserComponent browser = new BrowserComponent();
        browser.setDebugMode(true);
        browser.setURL("https://www.codenameone.com/");
        browser.addWebEventListener(BrowserComponent.onLoad, evt -> {
            browser.addJSCallback("window.myCallback = function(args) {callback.onSuccess(args)};"
                    , (args) -> {
                System.out.println("Hello: " + args);
            });
        });
        hi.add(BorderLayout.CENTER, browser);
        Button btn = new Button("Hello");
        btn.addActionListener(e -> {
            browser.execute("myCallback('Hello from Java')");
        });
        hi.add(BorderLayout.SOUTH, btn);
        hi.show();
    }
}

@shannah shannah merged commit 898f4d6 into master Feb 8, 2025
1 check passed
@shannah shannah deleted the feature/3868-wkwebview-inspectable branch February 8, 2025 14:48
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

Successfully merging this pull request may close these issues.

2 participants