【问题标题】:How to open a chrome window using a java program in a full screen mode/size?如何在全屏模式/大小下使用 java 程序打开 chrome 窗口?
【发布时间】:2018-03-31 20:34:08
【问题描述】:

我正在开发一个程序,该程序可以在多个 chrome 窗口中打开多个 URL,我应该在这些窗口中截取这些窗口的屏幕截图并写入文件。 到目前为止,我能够在不同的 chrome 窗口中打开 URL,但我不知道如何以全屏模式/大小打开这些窗口。这样可以正确截取屏幕截图。有人可以帮忙吗? 我的代码:

Runtime runtime = Runtime.getRuntime();
                try{//using try-catch as the target system might be of 32 bit or 64 bit
                    Process p = runtime.exec("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe -new-window "+url);
}catch(Exception ex){
                    Process p = runtime.exec("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe -new-window "+url);
 }

【问题讨论】:

    标签: java google-chrome


    【解决方案1】:

    试试这个:

    public static void main(String[] args) throws IOException {
            String path = "path/to/chrome.exe";
            Runtime rt = Runtime.getRuntime();
            Process pr1 = rt.exec(path + " --app=https://url1.com --start-maximized");
            Process pr2 = rt.exec(path + " --app=https://url2.com --start-maximized");
    }
    

    【讨论】:

    • 很抱歉,但它仍然没有以全尺寸打开。在它过去以任何随机尺寸打开之前,但在您的解决方案之后它以固定尺寸打开就是这样。
    • 尝试先关闭所有chrome的实例,然后运行程序。
    猜你喜欢
    • 1970-01-01
    • 2011-05-12
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多