简体   繁体   English

在应用程序启动之前,如何始终通过命令行参数将远程调试端口设置为基于 jxbrowser 的 chromium.exe?

[英]How to always set remote-debugging-port to jxbrowser based chromium.exe via command line args before the application start up?

I have a Windows based application (.exe based) which upon launch comes up with Win form for login.我有一个基于 Windows 的应用程序(基于 .exe),它在启动时会出现用于登录的 Win 表单。 Upon login, it loads the application and also loads the JxBrowser libs which launches an embedded chromium browser (I see in my task manager that Chromium.exe processes come up at this time).登录后,它会加载应用程序并加载启动嵌入式 chromium 浏览器的 JxBrowser 库(我在任务管理器中看到 Chromium.exe 进程此时出现)。 I plan to automate this embedded browser using selenium.我计划使用 selenium 自动化这个嵌入式浏览器。 So, I read about --remote-debugging-port option, so I could access it in Chrome using selenium using localhost:<remote-debugging-port> on which my application is launched.因此,我阅读了有关--remote-debugging-port选项的信息,因此我可以在 Chrome 中使用 selenium 使用localhost:<remote-debugging-port>在其上启动我的应用程序来访问它。

I tried the following things to set the remote-debugging-port to my Windows application.我尝试了以下方法将远程调试端口设置为我的 Windows 应用程序。

Option 1选项1

In my Windows application exe path, I start it up with --remote-debugging-port=9222.在我的 Windows 应用程序 exe 路径中,我使用 --remote-debugging-port=9222 启动它。 When I launch the application, and then it comes up with embedded browsers, I then open a chrome window and try navigating to localhost:9222, and I get a Connection Refused.当我启动应用程序时,它会出现嵌入式浏览器,然后我打开一个 chrome window 并尝试导航到 localhost:9222,我得到一个连接被拒绝。

I understand that somehow, within the application, when it launches the Chromium.exe processes, I need to send the remote-debugging-port in that Chromium.exe file.我知道,在应用程序中,当它启动 Chromium.exe 进程时,我需要在该 Chromium.exe 文件中发送远程调试端口。

Option 2选项 2

So, I create a shortcut for Chromium.exe, and add the --remote-debugging-port in the Target option of the shortcut.因此,我为 Chromium.exe 创建了一个快捷方式,并在快捷方式的Target选项中添加了 --remote-debugging-port。 Then I again launch my Windows based application (this time without remote debugging port at Win application level).然后我再次启动基于 Windows 的应用程序(这次在 Win 应用程序级别没有远程调试端口)。 However, once the application is fully loaded, and the embedded JxBrowser based Chromium windows come up (and task manager launches the Chromium.exe) process, when I launch Chrome window and navigate to localhost:9222, again I get Connection Refused.但是,一旦应用程序完全加载,并且基于嵌入式 JxBrowser 的 Chromium windows 出现(并且任务管理器启动 Chromium.exe)进程,当我启动 Chrome window 并导航到 localhost:9222 时,我再次得到 Connection Refused。

So, from the task manager, I then right-click on Chromium.exe process, and click on "Open File Location".因此,从任务管理器中,我右键单击 Chromium.exe 进程,然后单击“打开文件位置”。 It takes me to the Chromium.exe path.它把我带到 Chromium.exe 路径。 However, I had set the remote-debugging-port on the shortcut I created out of this Chromium.exe path, so I am not sure the application takes that (whether it needs to honor the remote-debugging-port from the shortcut of that actual exe path) into effect when it launches但是,我已经在我用这个 Chromium.exe 路径创建的快捷方式上设置了远程调试端口,所以我不确定应用程序是否接受它(它是否需要从那个快捷方式中接受远程调试端口实际的 exe 路径)在启动时生效

After trying multiple different things, I am really stuck as to how I can make my Windows application chromium based process start up automatically with remote-debugging on so I can perform the automation activities using Selenium Chromedriver using localhost:9222在尝试了多种不同的事情之后,我真的很想知道如何让我的 Windows 应用程序基于铬的进程在远程调试的情况下自动启动,这样我就可以使用 Selenium Chromedriver 使用 localhost:9222 执行自动化活动

Since I am unable to inspect anything on the JxBrowser based Chromium embedded browser in my Windows application, I really need to have this working.由于我无法在我的 Windows 应用程序中检查基于 JxBrowser 的 Chromium 嵌入式浏览器上的任何内容,因此我真的需要让它工作。

I went through the following article Automation for "Chrome Legacy Window" (Chromium) using Winium - however, this also does not give clarity as to how I can start my application with remote-debugging-port for the chromium process which comes up after the login to my windows process.我浏览了以下文章Automation for "Chrome Legacy Window" (Chromium) using Winium - 但是,这也没有明确说明我如何使用远程调试端口启动我的应用程序,用于在之后出现的 chromium 进程登录到我的 windows 进程。

Has anybody encountered scenario like this, and been able to perform remote-debugging?有没有人遇到过这样的情况,并且能够进行远程调试? Any help/advice would be really appreciated.任何帮助/建议将不胜感激。

Please let me know if any specific information is required?请让我知道是否需要任何具体信息?

The thing is that when Selenium launches your app, it passes the --remote-debugging-port=<port> command line argument to your program.问题是,当 Selenium 启动您的应用程序时,它会将--remote-debugging-port=<port>命令行参数传递给您的程序。 You need to forward this port to the Chromium engine launched by JxBrowser in your app.您需要将此端口转发到应用程序中JxBrowser启动的 Chromium 引擎。 The following example demonstrates how to do it:以下示例演示了如何执行此操作:

import static com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED;

import com.teamdev.jxbrowser.browser.Browser;
import com.teamdev.jxbrowser.engine.Engine;
import com.teamdev.jxbrowser.engine.EngineOptions;
import com.teamdev.jxbrowser.view.swing.BrowserView;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Optional;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

public final class App {

    private static final String REMOTE_DEBUGGING_PORT_ARG = "--remote-debugging-port=";

    public static void main(String[] args) {
        // Create a builder for EngineOptions.
        EngineOptions.Builder builder = EngineOptions.newBuilder(HARDWARE_ACCELERATED);

        // Pass the remote debugging port from the command line if it presents.
        remoteDebuggingPortFromCommandLine(args).ifPresent(builder::remoteDebuggingPort);

        // Creating and running Chromium engine.
        Engine engine = Engine.newInstance(builder.build());
        Browser browser = engine.newBrowser();

        SwingUtilities.invokeLater(() -> {
            // Creating Swing component for rendering web content
            // loaded in the given Browser instance.
            final BrowserView view = BrowserView.newInstance(browser);

            // Creating and displaying Swing app frame.
            JFrame frame = new JFrame("Hello World");
            // Close Engine and onClose app window
            frame.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    engine.close();
                }
            });
            frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            JTextField addressBar = new JTextField("https://google.com");
            addressBar.addActionListener(e ->
                    browser.navigation().loadUrl(addressBar.getText()));
            frame.add(addressBar, BorderLayout.NORTH);
            frame.add(view, BorderLayout.CENTER);
            frame.setSize(800, 500);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);

            browser.navigation().loadUrl(addressBar.getText());
        });
    }

    private static Optional<Integer> remoteDebuggingPortFromCommandLine(String[] args) {
        if (args.length > 0) {
            for (String arg : args) {
                if (arg.startsWith(REMOTE_DEBUGGING_PORT_ARG)) {
                    String port = arg.substring(REMOTE_DEBUGGING_PORT_ARG.length());
                    return Optional.of(Integer.parseInt(port));
                }
            }
        }
        return Optional.empty();
    }
}

I hope it helps )我希望它有帮助)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过命令行启动 spring-boot 应用程序? - How to start up spring-boot application via command line? 启动应用程序之前,Spring端口转发远程数据库 - Spring port Forwarding for remote database before start application 调试tomcat应用程序时如何在windows中启动tomcat调试端口 - how to start tomcat debug port in windows while debugging tomcat application Intellij-如何编辑JVM命令行参数以进行远程调试 - Intellij - How to edit JVM command line arguments for remote debugging 如何通过Eclipse中的远程Java应用程序调试来调试Groovy代码 - How to debug Groovy code via the remote Java application debugging in Eclipse Shell脚本:运行Java应用程序并通过脚本向其发送命令行args? - Shell script: running a java application and sending command-line args to it via the script? Java jdb远程调试命令行工具 - Java jdb remote debugging command line tool 如何通过 YourKit 命令行进行远程分析? - How to do remote profiling via YourKit command line? 如何通过命令行/批处理Args []将所有类型的SQL查询传递给Java? - How to pass all kind of SQL-Queries via Command Line/Batch Args[] into Java? JxBrowser 发布最新版本的 Chromium(版本 77)需要多长时间? - How long until JxBrowser ships the latest version of Chromium (version 77)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM