Class Example02

    • Method Summary

       
      Example Steps
      Modifier and Type Method
      static void main​(String[] argv)
      static void waitForLoad​(WebSocketSender pws, int tries, int ms)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • main

        🡇     🗕  🗗  🗖
        public static void main​(java.lang.String[] argv)
                         throws java.lang.Exception
        Run this method, save the image.
        Throws:
        java.lang.Exception
        Code:
        Exact Method Body:
         // Opening a WebSocket Browser-Connection to the currently running Chrome-Instance
         final WebSocketSender bws = Example01.STEP_01_openBrowserWebSocket();
        
         // Close any currently opened pages / tabs inside the browser
         Example01.STEP_02_closeAllPages(bws);
        
         // Open a Browser-Page (using 'bws') for reading Sam Altman's Wikipedia Profile
         final String targetID = Example01.STEP_03_openSamAltmanPage(bws);
        
         // Create / Build a WebSocket-Connection object to the newly opened Sam Altman Page.
         final WebSocketSender pws = Example01.STEP_04_getPageWebSocket(targetID);
        
         // Enable the Page domain
         System.out.println("\nPage.enable()");
         Page.enable(null /* Boolean */).exec(pws).await();
        
         // Chat-GPT and Gemini are fighting.  Chat-GPT told me to add this.
         RunTime.enable().exec(pws).await();
         waitForLoad(pws, 10, 1000);
        
         final String b64Img = Page
             // .captureScreenshot("png", null, null, null, null, null).exec(pws).await();
             .captureScreenshot()
             .accept("format", "png")
             .accept("fromSurface", true)
             .build()
             .exec(pws)
             .await();
        
         final BufferedImage img = IF.decodeBase64ToImage(b64Img, IF.JPG);
        
         ImageIO.write(img, "jpg", new File("image.jpg"));
        
         bws.disconnect();
         pws.disconnect();