001package Torello.Browser; 002 003import java.util.*; 004import javax.json.*; 005import javax.json.stream.*; 006import java.io.*; 007 008import java.lang.reflect.Method; 009import java.lang.reflect.Parameter; 010import java.util.function.Function; 011 012import Torello.Java.Additional.*; 013import Torello.Java.JSON.*; 014 015import static Torello.Java.JSON.JFlag.*; 016 017import Torello.Java.StrCmpr; 018import Torello.JavaDoc.StaticFunctional; 019import Torello.JavaDoc.JDHeaderBackgroundImg; 020import Torello.JavaDoc.Excuse; 021 022/** 023 * <SPAN CLASS=COPIEDJDK><B>Supports additional targets discovery and allows to attach to them.</B></SPAN> 024 * 025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE> 026 */ 027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION}) 028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE") 029public class Target 030{ 031 // ******************************************************************************************** 032 // ******************************************************************************************** 033 // Class Header Stuff 034 // ******************************************************************************************** 035 // ******************************************************************************************** 036 037 038 // No Pubic Constructors 039 private Target () { } 040 041 // These two Vector's are used by all the "Methods" exported by this class. java.lang.reflect 042 // is used to generate the JSON String's. It saves thousands of lines of Auto-Generated Code. 043 private static final Map<String, Vector<String>> parameterNames = new HashMap<>(); 044 private static final Map<String, Vector<Class<?>>> parameterTypes = new HashMap<>(); 045 046 // Some Methods do not take any parameters - for instance all the "enable()" and "disable()" 047 // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now, 048 // offically, two empty-vectors. One for String's, and the other for Classes. 049 050 private static final Vector<String> EMPTY_VEC_STR = new Vector<>(); 051 private static final Vector<Class<?>> EMPTY_VEC_CLASS = new Vector<>(); 052 053 static 054 { 055 for (Method m : Target.class.getMethods()) 056 { 057 // This doesn't work! The parameter names are all "arg0" ... "argN" 058 // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter! 059 // 060 // Vector<String> parameterNamesList = new Vector<>(); -- NOPE! 061 062 Vector<Class<?>> parameterTypesList = new Vector<>(); 063 064 for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType()); 065 066 parameterTypes.put( 067 m.getName(), 068 (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS 069 ); 070 } 071 } 072 073 static 074 { 075 Vector<String> v = null; 076 077 v = new Vector<String>(1); 078 parameterNames.put("activateTarget", v); 079 Collections.addAll(v, new String[] 080 { "targetId", }); 081 082 v = new Vector<String>(2); 083 parameterNames.put("attachToTarget", v); 084 Collections.addAll(v, new String[] 085 { "targetId", "flatten", }); 086 087 parameterNames.put("attachToBrowserTarget", EMPTY_VEC_STR); 088 089 v = new Vector<String>(1); 090 parameterNames.put("closeTarget", v); 091 Collections.addAll(v, new String[] 092 { "targetId", }); 093 094 v = new Vector<String>(2); 095 parameterNames.put("exposeDevToolsProtocol", v); 096 Collections.addAll(v, new String[] 097 { "targetId", "bindingName", }); 098 099 v = new Vector<String>(3); 100 parameterNames.put("createBrowserContext", v); 101 Collections.addAll(v, new String[] 102 { "disposeOnDetach", "proxyServer", "proxyBypassList", }); 103 104 parameterNames.put("getBrowserContexts", EMPTY_VEC_STR); 105 106 v = new Vector<String>(7); 107 parameterNames.put("createTarget", v); 108 Collections.addAll(v, new String[] 109 { "url", "width", "height", "browserContextId", "enableBeginFrameControl", "newWindow", "background", }); 110 111 v = new Vector<String>(2); 112 parameterNames.put("detachFromTarget", v); 113 Collections.addAll(v, new String[] 114 { "sessionId", "targetId", }); 115 116 v = new Vector<String>(1); 117 parameterNames.put("disposeBrowserContext", v); 118 Collections.addAll(v, new String[] 119 { "browserContextId", }); 120 121 v = new Vector<String>(1); 122 parameterNames.put("getTargetInfo", v); 123 Collections.addAll(v, new String[] 124 { "targetId", }); 125 126 parameterNames.put("getTargets", EMPTY_VEC_STR); 127 128 v = new Vector<String>(3); 129 parameterNames.put("sendMessageToTarget", v); 130 Collections.addAll(v, new String[] 131 { "message", "sessionId", "targetId", }); 132 133 v = new Vector<String>(3); 134 parameterNames.put("setAutoAttach", v); 135 Collections.addAll(v, new String[] 136 { "autoAttach", "waitForDebuggerOnStart", "flatten", }); 137 138 v = new Vector<String>(2); 139 parameterNames.put("autoAttachRelated", v); 140 Collections.addAll(v, new String[] 141 { "targetId", "waitForDebuggerOnStart", }); 142 143 v = new Vector<String>(1); 144 parameterNames.put("setDiscoverTargets", v); 145 Collections.addAll(v, new String[] 146 { "discover", }); 147 148 v = new Vector<String>(1); 149 parameterNames.put("setRemoteLocations", v); 150 Collections.addAll(v, new String[] 151 { "locations", }); 152 } 153 154 155 // ******************************************************************************************** 156 // ******************************************************************************************** 157 // Types - Static Inner Classes 158 // ******************************************************************************************** 159 // ******************************************************************************************** 160 161 // public static class TargetID => String 162 163 // public static class SessionID => String 164 165 /** <CODE>[No Description Provided by Google]</CODE> */ 166 public static class TargetInfo 167 extends BaseType 168 implements java.io.Serializable 169 { 170 /** For Object Serialization. java.io.Serializable */ 171 protected static final long serialVersionUID = 1; 172 173 public boolean[] optionals() 174 { return new boolean[] { false, false, false, false, false, true, false, true, true, }; } 175 176 /** <CODE>[No Description Provided by Google]</CODE> */ 177 public final String targetId; 178 179 /** <CODE>[No Description Provided by Google]</CODE> */ 180 public final String type; 181 182 /** <CODE>[No Description Provided by Google]</CODE> */ 183 public final String title; 184 185 /** <CODE>[No Description Provided by Google]</CODE> */ 186 public final String url; 187 188 /** Whether the target has an attached client. */ 189 public final boolean attached; 190 191 /** 192 * Opener target Id 193 * <BR /> 194 * <BR /><B>OPTIONAL</B> 195 */ 196 public final String openerId; 197 198 /** 199 * Whether the target has access to the originating window. 200 * <BR /> 201 * <BR /><B>EXPERIMENTAL</B> 202 */ 203 public final boolean canAccessOpener; 204 205 /** 206 * Frame id of originating window (is only set if target has an opener). 207 * <BR /> 208 * <BR /><B>OPTIONAL</B> 209 * <BR /><B>EXPERIMENTAL</B> 210 */ 211 public final String openerFrameId; 212 213 /** 214 * <CODE>[No Description Provided by Google]</CODE> 215 * <BR /> 216 * <BR /><B>OPTIONAL</B> 217 * <BR /><B>EXPERIMENTAL</B> 218 */ 219 public final String browserContextId; 220 221 /** 222 * Constructor 223 * 224 * @param targetId - 225 * 226 * @param type - 227 * 228 * @param title - 229 * 230 * @param url - 231 * 232 * @param attached Whether the target has an attached client. 233 * 234 * @param openerId Opener target Id 235 * <BR /><B>OPTIONAL</B> 236 * 237 * @param canAccessOpener Whether the target has access to the originating window. 238 * <BR /><B>EXPERIMENTAL</B> 239 * 240 * @param openerFrameId Frame id of originating window (is only set if target has an opener). 241 * <BR /><B>OPTIONAL</B> 242 * <BR /><B>EXPERIMENTAL</B> 243 * 244 * @param browserContextId - 245 * <BR /><B>OPTIONAL</B> 246 * <BR /><B>EXPERIMENTAL</B> 247 */ 248 public TargetInfo( 249 String targetId, String type, String title, String url, boolean attached, 250 String openerId, boolean canAccessOpener, String openerFrameId, 251 String browserContextId 252 ) 253 { 254 // Exception-Check(s) to ensure that if any parameters which are not declared as 255 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 256 257 if (targetId == null) THROWS.throwNPE("targetId"); 258 if (type == null) THROWS.throwNPE("type"); 259 if (title == null) THROWS.throwNPE("title"); 260 if (url == null) THROWS.throwNPE("url"); 261 262 this.targetId = targetId; 263 this.type = type; 264 this.title = title; 265 this.url = url; 266 this.attached = attached; 267 this.openerId = openerId; 268 this.canAccessOpener = canAccessOpener; 269 this.openerFrameId = openerFrameId; 270 this.browserContextId = browserContextId; 271 } 272 273 /** 274 * JSON Object Constructor 275 * @param jo A Json-Object having data about an instance of {@code 'TargetInfo'}. 276 */ 277 public TargetInfo (JsonObject jo) 278 { 279 this.targetId = ReadJSON.getString(jo, "targetId", false, true); 280 this.type = ReadJSON.getString(jo, "type", false, true); 281 this.title = ReadJSON.getString(jo, "title", false, true); 282 this.url = ReadJSON.getString(jo, "url", false, true); 283 this.attached = ReadPrimJSON.getBoolean(jo, "attached"); 284 this.openerId = ReadJSON.getString(jo, "openerId", true, false); 285 this.canAccessOpener = ReadPrimJSON.getBoolean(jo, "canAccessOpener"); 286 this.openerFrameId = ReadJSON.getString(jo, "openerFrameId", true, false); 287 this.browserContextId = ReadJSON.getString(jo, "browserContextId", true, false); 288 } 289 290 291 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 292 public boolean equals(Object other) 293 { 294 if (this == other) return true; 295 if (other == null) return false; 296 if (other.getClass() != this.getClass()) return false; 297 298 TargetInfo o = (TargetInfo) other; 299 300 return 301 Objects.equals(this.targetId, o.targetId) 302 && Objects.equals(this.type, o.type) 303 && Objects.equals(this.title, o.title) 304 && Objects.equals(this.url, o.url) 305 && (this.attached == o.attached) 306 && Objects.equals(this.openerId, o.openerId) 307 && (this.canAccessOpener == o.canAccessOpener) 308 && Objects.equals(this.openerFrameId, o.openerFrameId) 309 && Objects.equals(this.browserContextId, o.browserContextId); 310 } 311 312 /** Generates a Hash-Code for {@code 'this'} instance */ 313 public int hashCode() 314 { 315 return 316 Objects.hashCode(this.targetId) 317 + Objects.hashCode(this.type) 318 + Objects.hashCode(this.title) 319 + Objects.hashCode(this.url) 320 + (this.attached ? 1 : 0) 321 + Objects.hashCode(this.openerId) 322 + (this.canAccessOpener ? 1 : 0) 323 + Objects.hashCode(this.openerFrameId) 324 + Objects.hashCode(this.browserContextId); 325 } 326 } 327 328 /** 329 * <CODE>[No Description Provided by Google]</CODE> 330 * <BR /> 331 * <BR /><B>EXPERIMENTAL</B> 332 */ 333 public static class RemoteLocation 334 extends BaseType 335 implements java.io.Serializable 336 { 337 /** For Object Serialization. java.io.Serializable */ 338 protected static final long serialVersionUID = 1; 339 340 public boolean[] optionals() 341 { return new boolean[] { false, false, }; } 342 343 /** <CODE>[No Description Provided by Google]</CODE> */ 344 public final String host; 345 346 /** <CODE>[No Description Provided by Google]</CODE> */ 347 public final int port; 348 349 /** 350 * Constructor 351 * 352 * @param host - 353 * 354 * @param port - 355 */ 356 public RemoteLocation(String host, int port) 357 { 358 // Exception-Check(s) to ensure that if any parameters which are not declared as 359 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 360 361 if (host == null) THROWS.throwNPE("host"); 362 363 this.host = host; 364 this.port = port; 365 } 366 367 /** 368 * JSON Object Constructor 369 * @param jo A Json-Object having data about an instance of {@code 'RemoteLocation'}. 370 */ 371 public RemoteLocation (JsonObject jo) 372 { 373 this.host = ReadJSON.getString(jo, "host", false, true); 374 this.port = ReadPrimJSON.getInt(jo, "port"); 375 } 376 377 378 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 379 public boolean equals(Object other) 380 { 381 if (this == other) return true; 382 if (other == null) return false; 383 if (other.getClass() != this.getClass()) return false; 384 385 RemoteLocation o = (RemoteLocation) other; 386 387 return 388 Objects.equals(this.host, o.host) 389 && (this.port == o.port); 390 } 391 392 /** Generates a Hash-Code for {@code 'this'} instance */ 393 public int hashCode() 394 { 395 return 396 Objects.hashCode(this.host) 397 + this.port; 398 } 399 } 400 401 /** 402 * Issued when attached to target because of auto-attach or <CODE>attachToTarget</CODE> command. 403 * <BR /> 404 * <BR /><B>EXPERIMENTAL</B> 405 */ 406 public static class attachedToTarget 407 extends BrowserEvent 408 implements java.io.Serializable 409 { 410 /** For Object Serialization. java.io.Serializable */ 411 protected static final long serialVersionUID = 1; 412 413 public boolean[] optionals() 414 { return new boolean[] { false, false, false, }; } 415 416 /** Identifier assigned to the session used to send/receive messages. */ 417 public final String sessionId; 418 419 /** <CODE>[No Description Provided by Google]</CODE> */ 420 public final Target.TargetInfo targetInfo; 421 422 /** <CODE>[No Description Provided by Google]</CODE> */ 423 public final boolean waitingForDebugger; 424 425 /** 426 * Constructor 427 * 428 * @param sessionId Identifier assigned to the session used to send/receive messages. 429 * 430 * @param targetInfo - 431 * 432 * @param waitingForDebugger - 433 */ 434 public attachedToTarget 435 (String sessionId, Target.TargetInfo targetInfo, boolean waitingForDebugger) 436 { 437 super("Target", "attachedToTarget", 3); 438 439 // Exception-Check(s) to ensure that if any parameters which are not declared as 440 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 441 442 if (sessionId == null) THROWS.throwNPE("sessionId"); 443 if (targetInfo == null) THROWS.throwNPE("targetInfo"); 444 445 this.sessionId = sessionId; 446 this.targetInfo = targetInfo; 447 this.waitingForDebugger = waitingForDebugger; 448 } 449 450 /** 451 * JSON Object Constructor 452 * @param jo A Json-Object having data about an instance of {@code 'attachedToTarget'}. 453 */ 454 public attachedToTarget (JsonObject jo) 455 { 456 super("Target", "attachedToTarget", 3); 457 458 this.sessionId = ReadJSON.getString(jo, "sessionId", false, true); 459 this.targetInfo = ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true); 460 this.waitingForDebugger = ReadPrimJSON.getBoolean(jo, "waitingForDebugger"); 461 } 462 463 464 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 465 public boolean equals(Object other) 466 { 467 if (this == other) return true; 468 if (other == null) return false; 469 if (other.getClass() != this.getClass()) return false; 470 471 attachedToTarget o = (attachedToTarget) other; 472 473 return 474 Objects.equals(this.sessionId, o.sessionId) 475 && Objects.equals(this.targetInfo, o.targetInfo) 476 && (this.waitingForDebugger == o.waitingForDebugger); 477 } 478 479 /** Generates a Hash-Code for {@code 'this'} instance */ 480 public int hashCode() 481 { 482 return 483 Objects.hashCode(this.sessionId) 484 + this.targetInfo.hashCode() 485 + (this.waitingForDebugger ? 1 : 0); 486 } 487 } 488 489 /** 490 * Issued when detached from target for any reason (including <CODE>detachFromTarget</CODE> command). Can be 491 * issued multiple times per target if multiple sessions have been attached to it. 492 * <BR /> 493 * <BR /><B>EXPERIMENTAL</B> 494 */ 495 public static class detachedFromTarget 496 extends BrowserEvent 497 implements java.io.Serializable 498 { 499 /** For Object Serialization. java.io.Serializable */ 500 protected static final long serialVersionUID = 1; 501 502 public boolean[] optionals() 503 { return new boolean[] { false, true, }; } 504 505 /** Detached session identifier. */ 506 public final String sessionId; 507 508 /** 509 * Deprecated. 510 * <BR /> 511 * <BR /><B>OPTIONAL</B> 512 * <BR /><B>DEPRECATED</B> 513 */ 514 public final String targetId; 515 516 /** 517 * Constructor 518 * 519 * @param sessionId Detached session identifier. 520 * 521 * @param targetId Deprecated. 522 * <BR /><B>OPTIONAL</B> 523 * <BR /><B>DEPRECATED</B> 524 */ 525 public detachedFromTarget(String sessionId, String targetId) 526 { 527 super("Target", "detachedFromTarget", 2); 528 529 // Exception-Check(s) to ensure that if any parameters which are not declared as 530 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 531 532 if (sessionId == null) THROWS.throwNPE("sessionId"); 533 534 this.sessionId = sessionId; 535 this.targetId = targetId; 536 } 537 538 /** 539 * JSON Object Constructor 540 * @param jo A Json-Object having data about an instance of {@code 'detachedFromTarget'}. 541 */ 542 public detachedFromTarget (JsonObject jo) 543 { 544 super("Target", "detachedFromTarget", 2); 545 546 this.sessionId = ReadJSON.getString(jo, "sessionId", false, true); 547 this.targetId = ReadJSON.getString(jo, "targetId", true, false); 548 } 549 550 551 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 552 public boolean equals(Object other) 553 { 554 if (this == other) return true; 555 if (other == null) return false; 556 if (other.getClass() != this.getClass()) return false; 557 558 detachedFromTarget o = (detachedFromTarget) other; 559 560 return 561 Objects.equals(this.sessionId, o.sessionId) 562 && Objects.equals(this.targetId, o.targetId); 563 } 564 565 /** Generates a Hash-Code for {@code 'this'} instance */ 566 public int hashCode() 567 { 568 return 569 Objects.hashCode(this.sessionId) 570 + Objects.hashCode(this.targetId); 571 } 572 } 573 574 /** 575 * Notifies about a new protocol message received from the session (as reported in 576 * <CODE>attachedToTarget</CODE> event). 577 */ 578 public static class receivedMessageFromTarget 579 extends BrowserEvent 580 implements java.io.Serializable 581 { 582 /** For Object Serialization. java.io.Serializable */ 583 protected static final long serialVersionUID = 1; 584 585 public boolean[] optionals() 586 { return new boolean[] { false, false, true, }; } 587 588 /** Identifier of a session which sends a message. */ 589 public final String sessionId; 590 591 /** <CODE>[No Description Provided by Google]</CODE> */ 592 public final String message; 593 594 /** 595 * Deprecated. 596 * <BR /> 597 * <BR /><B>OPTIONAL</B> 598 * <BR /><B>DEPRECATED</B> 599 */ 600 public final String targetId; 601 602 /** 603 * Constructor 604 * 605 * @param sessionId Identifier of a session which sends a message. 606 * 607 * @param message - 608 * 609 * @param targetId Deprecated. 610 * <BR /><B>OPTIONAL</B> 611 * <BR /><B>DEPRECATED</B> 612 */ 613 public receivedMessageFromTarget(String sessionId, String message, String targetId) 614 { 615 super("Target", "receivedMessageFromTarget", 3); 616 617 // Exception-Check(s) to ensure that if any parameters which are not declared as 618 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 619 620 if (sessionId == null) THROWS.throwNPE("sessionId"); 621 if (message == null) THROWS.throwNPE("message"); 622 623 this.sessionId = sessionId; 624 this.message = message; 625 this.targetId = targetId; 626 } 627 628 /** 629 * JSON Object Constructor 630 * @param jo A Json-Object having data about an instance of {@code 'receivedMessageFromTarget'}. 631 */ 632 public receivedMessageFromTarget (JsonObject jo) 633 { 634 super("Target", "receivedMessageFromTarget", 3); 635 636 this.sessionId = ReadJSON.getString(jo, "sessionId", false, true); 637 this.message = ReadJSON.getString(jo, "message", false, true); 638 this.targetId = ReadJSON.getString(jo, "targetId", true, false); 639 } 640 641 642 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 643 public boolean equals(Object other) 644 { 645 if (this == other) return true; 646 if (other == null) return false; 647 if (other.getClass() != this.getClass()) return false; 648 649 receivedMessageFromTarget o = (receivedMessageFromTarget) other; 650 651 return 652 Objects.equals(this.sessionId, o.sessionId) 653 && Objects.equals(this.message, o.message) 654 && Objects.equals(this.targetId, o.targetId); 655 } 656 657 /** Generates a Hash-Code for {@code 'this'} instance */ 658 public int hashCode() 659 { 660 return 661 Objects.hashCode(this.sessionId) 662 + Objects.hashCode(this.message) 663 + Objects.hashCode(this.targetId); 664 } 665 } 666 667 /** Issued when a possible inspection target is created. */ 668 public static class targetCreated 669 extends BrowserEvent 670 implements java.io.Serializable 671 { 672 /** For Object Serialization. java.io.Serializable */ 673 protected static final long serialVersionUID = 1; 674 675 public boolean[] optionals() 676 { return new boolean[] { false, }; } 677 678 /** <CODE>[No Description Provided by Google]</CODE> */ 679 public final Target.TargetInfo targetInfo; 680 681 /** 682 * Constructor 683 * 684 * @param targetInfo - 685 */ 686 public targetCreated(Target.TargetInfo targetInfo) 687 { 688 super("Target", "targetCreated", 1); 689 690 // Exception-Check(s) to ensure that if any parameters which are not declared as 691 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 692 693 if (targetInfo == null) THROWS.throwNPE("targetInfo"); 694 695 this.targetInfo = targetInfo; 696 } 697 698 /** 699 * JSON Object Constructor 700 * @param jo A Json-Object having data about an instance of {@code 'targetCreated'}. 701 */ 702 public targetCreated (JsonObject jo) 703 { 704 super("Target", "targetCreated", 1); 705 706 this.targetInfo = ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true); 707 } 708 709 710 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 711 public boolean equals(Object other) 712 { 713 if (this == other) return true; 714 if (other == null) return false; 715 if (other.getClass() != this.getClass()) return false; 716 717 targetCreated o = (targetCreated) other; 718 719 return 720 Objects.equals(this.targetInfo, o.targetInfo); 721 } 722 723 /** Generates a Hash-Code for {@code 'this'} instance */ 724 public int hashCode() 725 { 726 return 727 this.targetInfo.hashCode(); 728 } 729 } 730 731 /** Issued when a target is destroyed. */ 732 public static class targetDestroyed 733 extends BrowserEvent 734 implements java.io.Serializable 735 { 736 /** For Object Serialization. java.io.Serializable */ 737 protected static final long serialVersionUID = 1; 738 739 public boolean[] optionals() 740 { return new boolean[] { false, }; } 741 742 /** <CODE>[No Description Provided by Google]</CODE> */ 743 public final String targetId; 744 745 /** 746 * Constructor 747 * 748 * @param targetId - 749 */ 750 public targetDestroyed(String targetId) 751 { 752 super("Target", "targetDestroyed", 1); 753 754 // Exception-Check(s) to ensure that if any parameters which are not declared as 755 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 756 757 if (targetId == null) THROWS.throwNPE("targetId"); 758 759 this.targetId = targetId; 760 } 761 762 /** 763 * JSON Object Constructor 764 * @param jo A Json-Object having data about an instance of {@code 'targetDestroyed'}. 765 */ 766 public targetDestroyed (JsonObject jo) 767 { 768 super("Target", "targetDestroyed", 1); 769 770 this.targetId = ReadJSON.getString(jo, "targetId", false, true); 771 } 772 773 774 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 775 public boolean equals(Object other) 776 { 777 if (this == other) return true; 778 if (other == null) return false; 779 if (other.getClass() != this.getClass()) return false; 780 781 targetDestroyed o = (targetDestroyed) other; 782 783 return 784 Objects.equals(this.targetId, o.targetId); 785 } 786 787 /** Generates a Hash-Code for {@code 'this'} instance */ 788 public int hashCode() 789 { 790 return 791 Objects.hashCode(this.targetId); 792 } 793 } 794 795 /** Issued when a target has crashed. */ 796 public static class targetCrashed 797 extends BrowserEvent 798 implements java.io.Serializable 799 { 800 /** For Object Serialization. java.io.Serializable */ 801 protected static final long serialVersionUID = 1; 802 803 public boolean[] optionals() 804 { return new boolean[] { false, false, false, }; } 805 806 /** <CODE>[No Description Provided by Google]</CODE> */ 807 public final String targetId; 808 809 /** Termination status type. */ 810 public final String status; 811 812 /** Termination error code. */ 813 public final int errorCode; 814 815 /** 816 * Constructor 817 * 818 * @param targetId - 819 * 820 * @param status Termination status type. 821 * 822 * @param errorCode Termination error code. 823 */ 824 public targetCrashed(String targetId, String status, int errorCode) 825 { 826 super("Target", "targetCrashed", 3); 827 828 // Exception-Check(s) to ensure that if any parameters which are not declared as 829 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 830 831 if (targetId == null) THROWS.throwNPE("targetId"); 832 if (status == null) THROWS.throwNPE("status"); 833 834 this.targetId = targetId; 835 this.status = status; 836 this.errorCode = errorCode; 837 } 838 839 /** 840 * JSON Object Constructor 841 * @param jo A Json-Object having data about an instance of {@code 'targetCrashed'}. 842 */ 843 public targetCrashed (JsonObject jo) 844 { 845 super("Target", "targetCrashed", 3); 846 847 this.targetId = ReadJSON.getString(jo, "targetId", false, true); 848 this.status = ReadJSON.getString(jo, "status", false, true); 849 this.errorCode = ReadPrimJSON.getInt(jo, "errorCode"); 850 } 851 852 853 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 854 public boolean equals(Object other) 855 { 856 if (this == other) return true; 857 if (other == null) return false; 858 if (other.getClass() != this.getClass()) return false; 859 860 targetCrashed o = (targetCrashed) other; 861 862 return 863 Objects.equals(this.targetId, o.targetId) 864 && Objects.equals(this.status, o.status) 865 && (this.errorCode == o.errorCode); 866 } 867 868 /** Generates a Hash-Code for {@code 'this'} instance */ 869 public int hashCode() 870 { 871 return 872 Objects.hashCode(this.targetId) 873 + Objects.hashCode(this.status) 874 + this.errorCode; 875 } 876 } 877 878 /** 879 * Issued when some information about a target has changed. This only happens between 880 * <CODE>targetCreated</CODE> and <CODE>targetDestroyed</CODE>. 881 */ 882 public static class targetInfoChanged 883 extends BrowserEvent 884 implements java.io.Serializable 885 { 886 /** For Object Serialization. java.io.Serializable */ 887 protected static final long serialVersionUID = 1; 888 889 public boolean[] optionals() 890 { return new boolean[] { false, }; } 891 892 /** <CODE>[No Description Provided by Google]</CODE> */ 893 public final Target.TargetInfo targetInfo; 894 895 /** 896 * Constructor 897 * 898 * @param targetInfo - 899 */ 900 public targetInfoChanged(Target.TargetInfo targetInfo) 901 { 902 super("Target", "targetInfoChanged", 1); 903 904 // Exception-Check(s) to ensure that if any parameters which are not declared as 905 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 906 907 if (targetInfo == null) THROWS.throwNPE("targetInfo"); 908 909 this.targetInfo = targetInfo; 910 } 911 912 /** 913 * JSON Object Constructor 914 * @param jo A Json-Object having data about an instance of {@code 'targetInfoChanged'}. 915 */ 916 public targetInfoChanged (JsonObject jo) 917 { 918 super("Target", "targetInfoChanged", 1); 919 920 this.targetInfo = ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true); 921 } 922 923 924 /** Checks whether {@code 'this'} equals an input Java-{@code Object} */ 925 public boolean equals(Object other) 926 { 927 if (this == other) return true; 928 if (other == null) return false; 929 if (other.getClass() != this.getClass()) return false; 930 931 targetInfoChanged o = (targetInfoChanged) other; 932 933 return 934 Objects.equals(this.targetInfo, o.targetInfo); 935 } 936 937 /** Generates a Hash-Code for {@code 'this'} instance */ 938 public int hashCode() 939 { 940 return 941 this.targetInfo.hashCode(); 942 } 943 } 944 945 946 // Counter for keeping the WebSocket Request ID's distinct. 947 private static int counter = 1; 948 949 /** 950 * Activates (focuses) the target. 951 * 952 * @param targetId - 953 * 954 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 955 * {@link Ret0}></CODE> 956 * 957 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 958 * browser receives the invocation-request. 959 * 960 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 961 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 962 * {@code >} to ensure the Browser Function has run to completion. 963 */ 964 public static Script<String, JsonObject, Ret0> activateTarget(String targetId) 965 { 966 // Exception-Check(s) to ensure that if any parameters which are not declared as 967 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 968 969 if (targetId == null) THROWS.throwNPE("targetId"); 970 971 final int webSocketID = 39000000 + counter++; 972 final boolean[] optionals = { false, }; 973 974 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 975 String requestJSON = WriteJSON.get( 976 parameterTypes.get("activateTarget"), 977 parameterNames.get("activateTarget"), 978 optionals, webSocketID, 979 "Target.activateTarget", 980 targetId 981 ); 982 983 // This Remote Command does not have a Return-Value. 984 return new Script<> 985 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 986 } 987 988 /** 989 * Attaches to the target with given id. 990 * 991 * @param targetId - 992 * 993 * @param flatten 994 * Enables "flat" access to the session via specifying sessionId attribute in the commands. 995 * We plan to make this the default, deprecate non-flattened mode, 996 * and eventually retire it. See crbug.com/991325. 997 * <BR /><B>OPTIONAL</B> 998 * 999 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1000 * String></CODE> 1001 * 1002 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1003 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1004 * String></CODE> will be returned. 1005 * 1006 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1007 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1008 * may be retrieved.</I> 1009 * 1010 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1011 * <BR /><BR /><UL CLASS=JDUL> 1012 * <LI><CODE>String (<B>sessionId</B></CODE>) 1013 * <BR />Id assigned to the session. 1014 * </LI> 1015 * </UL> */ 1016 public static Script<String, JsonObject, String> attachToTarget 1017 (String targetId, Boolean flatten) 1018 { 1019 // Exception-Check(s) to ensure that if any parameters which are not declared as 1020 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1021 1022 if (targetId == null) THROWS.throwNPE("targetId"); 1023 1024 final int webSocketID = 39001000 + counter++; 1025 final boolean[] optionals = { false, true, }; 1026 1027 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1028 String requestJSON = WriteJSON.get( 1029 parameterTypes.get("attachToTarget"), 1030 parameterNames.get("attachToTarget"), 1031 optionals, webSocketID, 1032 "Target.attachToTarget", 1033 targetId, flatten 1034 ); 1035 1036 // 'JSON Binding' ... Converts Browser Response-JSON to 'String' 1037 Function<JsonObject, String> responseProcessor = (JsonObject jo) -> 1038 ReadJSON.getString(jo, "sessionId", false, true); 1039 1040 return new Script<>(webSocketID, requestJSON, responseProcessor); 1041 } 1042 1043 /** 1044 * Attaches to the browser target, only uses flat sessionId mode. 1045 * <BR /><B>EXPERIMENTAL</B> 1046 * 1047 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1048 * String></CODE> 1049 * 1050 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1051 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1052 * String></CODE> will be returned. 1053 * 1054 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1055 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1056 * may be retrieved.</I> 1057 * 1058 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1059 * <BR /><BR /><UL CLASS=JDUL> 1060 * <LI><CODE>String (<B>sessionId</B></CODE>) 1061 * <BR />Id assigned to the session. 1062 * </LI> 1063 * </UL> */ 1064 public static Script<String, JsonObject, String> attachToBrowserTarget() 1065 { 1066 final int webSocketID = 39002000 + counter++; 1067 final boolean[] optionals = new boolean[0]; 1068 1069 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1070 String requestJSON = WriteJSON.get( 1071 parameterTypes.get("attachToBrowserTarget"), 1072 parameterNames.get("attachToBrowserTarget"), 1073 optionals, webSocketID, 1074 "Target.attachToBrowserTarget" 1075 ); 1076 1077 // 'JSON Binding' ... Converts Browser Response-JSON to 'String' 1078 Function<JsonObject, String> responseProcessor = (JsonObject jo) -> 1079 ReadJSON.getString(jo, "sessionId", false, true); 1080 1081 return new Script<>(webSocketID, requestJSON, responseProcessor); 1082 } 1083 1084 /** 1085 * Closes the target. If the target is a page that gets closed too. 1086 * 1087 * @param targetId - 1088 * 1089 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1090 * Boolean></CODE> 1091 * 1092 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1093 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1094 * Boolean></CODE> will be returned. 1095 * 1096 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1097 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1098 * may be retrieved.</I> 1099 * 1100 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1101 * <BR /><BR /><UL CLASS=JDUL> 1102 * <LI><CODE>Boolean (<B>success</B></CODE>) 1103 * <BR />Always set to true. If an error occurs, the response indicates protocol error. 1104 * </LI> 1105 * </UL> */ 1106 public static Script<String, JsonObject, Boolean> closeTarget(String targetId) 1107 { 1108 // Exception-Check(s) to ensure that if any parameters which are not declared as 1109 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1110 1111 if (targetId == null) THROWS.throwNPE("targetId"); 1112 1113 final int webSocketID = 39003000 + counter++; 1114 final boolean[] optionals = { false, }; 1115 1116 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1117 String requestJSON = WriteJSON.get( 1118 parameterTypes.get("closeTarget"), 1119 parameterNames.get("closeTarget"), 1120 optionals, webSocketID, 1121 "Target.closeTarget", 1122 targetId 1123 ); 1124 1125 // 'JSON Binding' ... Converts Browser Response-JSON to 'Boolean' 1126 Function<JsonObject, Boolean> responseProcessor = (JsonObject jo) -> 1127 ReadPrimJSON.getBoolean(jo, "success"); 1128 1129 return new Script<>(webSocketID, requestJSON, responseProcessor); 1130 } 1131 1132 /** 1133 * Inject object to the target's main frame that provides a communication 1134 * channel with browser target. 1135 * 1136 * Injected object will be available as <CODE>window[bindingName]</CODE>. 1137 * 1138 * The object has the follwing API: 1139 * - <CODE>binding.send(json)</CODE> - a method to send messages over the remote debugging protocol 1140 * - <CODE>binding.onmessage = json => handleMessage(json)</CODE> - a callback that will be called for the protocol notifications and command responses. 1141 * <BR /><B>EXPERIMENTAL</B> 1142 * 1143 * @param targetId - 1144 * 1145 * @param bindingName Binding name, 'cdp' if not specified. 1146 * <BR /><B>OPTIONAL</B> 1147 * 1148 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1149 * {@link Ret0}></CODE> 1150 * 1151 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1152 * browser receives the invocation-request. 1153 * 1154 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1155 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1156 * {@code >} to ensure the Browser Function has run to completion. 1157 */ 1158 public static Script<String, JsonObject, Ret0> exposeDevToolsProtocol 1159 (String targetId, String bindingName) 1160 { 1161 // Exception-Check(s) to ensure that if any parameters which are not declared as 1162 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1163 1164 if (targetId == null) THROWS.throwNPE("targetId"); 1165 1166 final int webSocketID = 39004000 + counter++; 1167 final boolean[] optionals = { false, true, }; 1168 1169 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1170 String requestJSON = WriteJSON.get( 1171 parameterTypes.get("exposeDevToolsProtocol"), 1172 parameterNames.get("exposeDevToolsProtocol"), 1173 optionals, webSocketID, 1174 "Target.exposeDevToolsProtocol", 1175 targetId, bindingName 1176 ); 1177 1178 // This Remote Command does not have a Return-Value. 1179 return new Script<> 1180 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1181 } 1182 1183 /** 1184 * Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than 1185 * one. 1186 * <BR /><B>EXPERIMENTAL</B> 1187 * 1188 * @param disposeOnDetach If specified, disposes this context when debugging session disconnects. 1189 * <BR /><B>OPTIONAL</B> 1190 * 1191 * @param proxyServer Proxy server, similar to the one passed to --proxy-server 1192 * <BR /><B>OPTIONAL</B> 1193 * 1194 * @param proxyBypassList Proxy bypass list, similar to the one passed to --proxy-bypass-list 1195 * <BR /><B>OPTIONAL</B> 1196 * 1197 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1198 * String></CODE> 1199 * 1200 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1201 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1202 * String></CODE> will be returned. 1203 * 1204 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1205 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1206 * may be retrieved.</I> 1207 * 1208 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1209 * <BR /><BR /><UL CLASS=JDUL> 1210 * <LI><CODE>String (<B>browserContextId</B></CODE>) 1211 * <BR />The id of the context created. 1212 * </LI> 1213 * </UL> */ 1214 public static Script<String, JsonObject, String> createBrowserContext 1215 (Boolean disposeOnDetach, String proxyServer, String proxyBypassList) 1216 { 1217 final int webSocketID = 39005000 + counter++; 1218 final boolean[] optionals = { true, true, true, }; 1219 1220 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1221 String requestJSON = WriteJSON.get( 1222 parameterTypes.get("createBrowserContext"), 1223 parameterNames.get("createBrowserContext"), 1224 optionals, webSocketID, 1225 "Target.createBrowserContext", 1226 disposeOnDetach, proxyServer, proxyBypassList 1227 ); 1228 1229 // 'JSON Binding' ... Converts Browser Response-JSON to 'String' 1230 Function<JsonObject, String> responseProcessor = (JsonObject jo) -> 1231 ReadJSON.getString(jo, "browserContextId", false, true); 1232 1233 return new Script<>(webSocketID, requestJSON, responseProcessor); 1234 } 1235 1236 /** 1237 * Returns all browser contexts created with <CODE>Target.createBrowserContext</CODE> method. 1238 * <BR /><B>EXPERIMENTAL</B> 1239 * 1240 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1241 * String[]></CODE> 1242 * 1243 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1244 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1245 * String[]></CODE> will be returned. 1246 * 1247 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1248 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1249 * may be retrieved.</I> 1250 * 1251 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1252 * <BR /><BR /><UL CLASS=JDUL> 1253 * <LI><CODE>String[] (<B>browserContextIds</B></CODE>) 1254 * <BR />An array of browser context ids. 1255 * </LI> 1256 * </UL> */ 1257 public static Script<String, JsonObject, String[]> getBrowserContexts() 1258 { 1259 final int webSocketID = 39006000 + counter++; 1260 final boolean[] optionals = new boolean[0]; 1261 1262 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1263 String requestJSON = WriteJSON.get( 1264 parameterTypes.get("getBrowserContexts"), 1265 parameterNames.get("getBrowserContexts"), 1266 optionals, webSocketID, 1267 "Target.getBrowserContexts" 1268 ); 1269 1270 // 'JSON Binding' ... Converts Browser Response-JSON to 'String[]' 1271 Function<JsonObject, String[]> responseProcessor = (JsonObject jo) -> 1272 (jo.getJsonArray("browserContextIds") == null) 1273 ? null 1274 : RJArrIntoStream.strArr(jo.getJsonArray("browserContextIds"), null, 0).toArray(String[]::new); 1275 1276 return new Script<>(webSocketID, requestJSON, responseProcessor); 1277 } 1278 1279 /** 1280 * Creates a new page. 1281 * 1282 * @param url The initial URL the page will be navigated to. An empty string indicates about:blank. 1283 * 1284 * @param width Frame width in DIP (headless chrome only). 1285 * <BR /><B>OPTIONAL</B> 1286 * 1287 * @param height Frame height in DIP (headless chrome only). 1288 * <BR /><B>OPTIONAL</B> 1289 * 1290 * @param browserContextId The browser context to create the page in. 1291 * <BR /><B>OPTIONAL</B> 1292 * <BR /><B>EXPERIMENTAL</B> 1293 * 1294 * @param enableBeginFrameControl 1295 * Whether BeginFrames for this target will be controlled via DevTools (headless chrome only, 1296 * not supported on MacOS yet, false by default). 1297 * <BR /><B>OPTIONAL</B> 1298 * <BR /><B>EXPERIMENTAL</B> 1299 * 1300 * @param newWindow Whether to create a new Window or Tab (chrome-only, false by default). 1301 * <BR /><B>OPTIONAL</B> 1302 * 1303 * @param background 1304 * Whether to create the target in background or foreground (chrome-only, 1305 * false by default). 1306 * <BR /><B>OPTIONAL</B> 1307 * 1308 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1309 * String></CODE> 1310 * 1311 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1312 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1313 * String></CODE> will be returned. 1314 * 1315 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1316 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1317 * may be retrieved.</I> 1318 * 1319 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1320 * <BR /><BR /><UL CLASS=JDUL> 1321 * <LI><CODE>String (<B>targetId</B></CODE>) 1322 * <BR />The id of the page opened. 1323 * </LI> 1324 * </UL> */ 1325 public static Script<String, JsonObject, String> createTarget( 1326 String url, Integer width, Integer height, String browserContextId, 1327 Boolean enableBeginFrameControl, Boolean newWindow, Boolean background 1328 ) 1329 { 1330 // Exception-Check(s) to ensure that if any parameters which are not declared as 1331 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1332 1333 if (url == null) THROWS.throwNPE("url"); 1334 1335 final int webSocketID = 39007000 + counter++; 1336 final boolean[] optionals = { false, true, true, true, true, true, true, }; 1337 1338 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1339 String requestJSON = WriteJSON.get( 1340 parameterTypes.get("createTarget"), 1341 parameterNames.get("createTarget"), 1342 optionals, webSocketID, 1343 "Target.createTarget", 1344 url, width, height, browserContextId, enableBeginFrameControl, newWindow, background 1345 ); 1346 1347 // 'JSON Binding' ... Converts Browser Response-JSON to 'String' 1348 Function<JsonObject, String> responseProcessor = (JsonObject jo) -> 1349 ReadJSON.getString(jo, "targetId", false, true); 1350 1351 return new Script<>(webSocketID, requestJSON, responseProcessor); 1352 } 1353 1354 /** 1355 * Detaches session with given id. 1356 * 1357 * @param sessionId Session to detach. 1358 * <BR /><B>OPTIONAL</B> 1359 * 1360 * @param targetId Deprecated. 1361 * <BR /><B>OPTIONAL</B> 1362 * <BR /><B>DEPRECATED</B> 1363 * 1364 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1365 * {@link Ret0}></CODE> 1366 * 1367 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1368 * browser receives the invocation-request. 1369 * 1370 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1371 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1372 * {@code >} to ensure the Browser Function has run to completion. 1373 */ 1374 public static Script<String, JsonObject, Ret0> detachFromTarget 1375 (String sessionId, String targetId) 1376 { 1377 final int webSocketID = 39008000 + counter++; 1378 final boolean[] optionals = { true, true, }; 1379 1380 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1381 String requestJSON = WriteJSON.get( 1382 parameterTypes.get("detachFromTarget"), 1383 parameterNames.get("detachFromTarget"), 1384 optionals, webSocketID, 1385 "Target.detachFromTarget", 1386 sessionId, targetId 1387 ); 1388 1389 // This Remote Command does not have a Return-Value. 1390 return new Script<> 1391 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1392 } 1393 1394 /** 1395 * Deletes a BrowserContext. All the belonging pages will be closed without calling their 1396 * beforeunload hooks. 1397 * <BR /><B>EXPERIMENTAL</B> 1398 * 1399 * @param browserContextId - 1400 * 1401 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1402 * {@link Ret0}></CODE> 1403 * 1404 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1405 * browser receives the invocation-request. 1406 * 1407 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1408 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1409 * {@code >} to ensure the Browser Function has run to completion. 1410 */ 1411 public static Script<String, JsonObject, Ret0> disposeBrowserContext 1412 (String browserContextId) 1413 { 1414 // Exception-Check(s) to ensure that if any parameters which are not declared as 1415 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1416 1417 if (browserContextId == null) THROWS.throwNPE("browserContextId"); 1418 1419 final int webSocketID = 39009000 + counter++; 1420 final boolean[] optionals = { false, }; 1421 1422 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1423 String requestJSON = WriteJSON.get( 1424 parameterTypes.get("disposeBrowserContext"), 1425 parameterNames.get("disposeBrowserContext"), 1426 optionals, webSocketID, 1427 "Target.disposeBrowserContext", 1428 browserContextId 1429 ); 1430 1431 // This Remote Command does not have a Return-Value. 1432 return new Script<> 1433 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1434 } 1435 1436 /** 1437 * Returns information about a target. 1438 * <BR /><B>EXPERIMENTAL</B> 1439 * 1440 * @param targetId - 1441 * <BR /><B>OPTIONAL</B> 1442 * 1443 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1444 * {@link Target.TargetInfo}></CODE> 1445 * 1446 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1447 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1448 * {@link Target.TargetInfo}></CODE> will be returned. 1449 * 1450 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1451 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1452 * may be retrieved.</I> 1453 * 1454 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1455 * <BR /><BR /><UL CLASS=JDUL> 1456 * <LI><CODE>{@link Target.TargetInfo} (<B>targetInfo</B></CODE>) 1457 * <BR />- 1458 * </LI> 1459 * </UL> */ 1460 public static Script<String, JsonObject, Target.TargetInfo> getTargetInfo(String targetId) 1461 { 1462 final int webSocketID = 39010000 + counter++; 1463 final boolean[] optionals = { true, }; 1464 1465 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1466 String requestJSON = WriteJSON.get( 1467 parameterTypes.get("getTargetInfo"), 1468 parameterNames.get("getTargetInfo"), 1469 optionals, webSocketID, 1470 "Target.getTargetInfo", 1471 targetId 1472 ); 1473 1474 // 'JSON Binding' ... Converts Browser Response-JSON to 'Target.TargetInfo' 1475 Function<JsonObject, Target.TargetInfo> responseProcessor = (JsonObject jo) -> 1476 ReadJSON.getObject(jo, "targetInfo", Target.TargetInfo.class, false, true); 1477 1478 return new Script<>(webSocketID, requestJSON, responseProcessor); 1479 } 1480 1481 /** 1482 * Retrieves a list of available targets. 1483 * 1484 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1485 * {@link Target.TargetInfo}[]></CODE> 1486 * 1487 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 1488 * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE><JsonObject, 1489 * {@link Target.TargetInfo}[]></CODE> will be returned. 1490 * 1491 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 1492 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 1493 * may be retrieved.</I> 1494 * 1495 * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B> 1496 * <BR /><BR /><UL CLASS=JDUL> 1497 * <LI><CODE>{@link Target.TargetInfo}[] (<B>targetInfos</B></CODE>) 1498 * <BR />The list of targets. 1499 * </LI> 1500 * </UL> */ 1501 public static Script<String, JsonObject, Target.TargetInfo[]> getTargets() 1502 { 1503 final int webSocketID = 39011000 + counter++; 1504 final boolean[] optionals = new boolean[0]; 1505 1506 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1507 String requestJSON = WriteJSON.get( 1508 parameterTypes.get("getTargets"), 1509 parameterNames.get("getTargets"), 1510 optionals, webSocketID, 1511 "Target.getTargets" 1512 ); 1513 1514 // 'JSON Binding' ... Converts Browser Response-JSON to 'Target.TargetInfo[]' 1515 Function<JsonObject, Target.TargetInfo[]> responseProcessor = (JsonObject jo) -> 1516 (jo.getJsonArray("targetInfos") == null) 1517 ? null 1518 : RJArrIntoStream.objArr(jo.getJsonArray("targetInfos"), null, 0, Target.TargetInfo.class).toArray(Target.TargetInfo[]::new); 1519 1520 return new Script<>(webSocketID, requestJSON, responseProcessor); 1521 } 1522 1523 /** 1524 * Sends protocol message over session with given id. 1525 * Consider using flat mode instead; see commands attachToTarget, setAutoAttach, 1526 * and crbug.com/991325. 1527 * <BR /><B>DEPRECATED</B> 1528 * 1529 * @param message - 1530 * 1531 * @param sessionId Identifier of the session. 1532 * <BR /><B>OPTIONAL</B> 1533 * 1534 * @param targetId Deprecated. 1535 * <BR /><B>OPTIONAL</B> 1536 * <BR /><B>DEPRECATED</B> 1537 * 1538 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1539 * {@link Ret0}></CODE> 1540 * 1541 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1542 * browser receives the invocation-request. 1543 * 1544 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1545 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1546 * {@code >} to ensure the Browser Function has run to completion. 1547 */ 1548 public static Script<String, JsonObject, Ret0> sendMessageToTarget 1549 (String message, String sessionId, String targetId) 1550 { 1551 // Exception-Check(s) to ensure that if any parameters which are not declared as 1552 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1553 1554 if (message == null) THROWS.throwNPE("message"); 1555 1556 final int webSocketID = 39012000 + counter++; 1557 final boolean[] optionals = { false, true, true, }; 1558 1559 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1560 String requestJSON = WriteJSON.get( 1561 parameterTypes.get("sendMessageToTarget"), 1562 parameterNames.get("sendMessageToTarget"), 1563 optionals, webSocketID, 1564 "Target.sendMessageToTarget", 1565 message, sessionId, targetId 1566 ); 1567 1568 // This Remote Command does not have a Return-Value. 1569 return new Script<> 1570 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1571 } 1572 1573 /** 1574 * Controls whether to automatically attach to new targets which are considered to be related to 1575 * this one. When turned on, attaches to all existing related targets as well. When turned off, 1576 * automatically detaches from all currently attached targets. 1577 * This also clears all targets added by <CODE>autoAttachRelated</CODE> from the list of targets to watch 1578 * for creation of related targets. 1579 * <BR /><B>EXPERIMENTAL</B> 1580 * 1581 * @param autoAttach Whether to auto-attach to related targets. 1582 * 1583 * @param waitForDebuggerOnStart 1584 * Whether to pause new targets when attaching to them. Use <CODE>RunTime.runIfWaitingForDebugger</CODE> 1585 * to run paused targets. 1586 * 1587 * @param flatten 1588 * Enables "flat" access to the session via specifying sessionId attribute in the commands. 1589 * We plan to make this the default, deprecate non-flattened mode, 1590 * and eventually retire it. See crbug.com/991325. 1591 * <BR /><B>OPTIONAL</B> 1592 * 1593 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1594 * {@link Ret0}></CODE> 1595 * 1596 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1597 * browser receives the invocation-request. 1598 * 1599 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1600 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1601 * {@code >} to ensure the Browser Function has run to completion. 1602 */ 1603 public static Script<String, JsonObject, Ret0> setAutoAttach 1604 (boolean autoAttach, boolean waitForDebuggerOnStart, Boolean flatten) 1605 { 1606 final int webSocketID = 39013000 + counter++; 1607 final boolean[] optionals = { false, false, true, }; 1608 1609 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1610 String requestJSON = WriteJSON.get( 1611 parameterTypes.get("setAutoAttach"), 1612 parameterNames.get("setAutoAttach"), 1613 optionals, webSocketID, 1614 "Target.setAutoAttach", 1615 autoAttach, waitForDebuggerOnStart, flatten 1616 ); 1617 1618 // This Remote Command does not have a Return-Value. 1619 return new Script<> 1620 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1621 } 1622 1623 /** 1624 * Adds the specified target to the list of targets that will be monitored for any related target 1625 * creation (such as child frames, child workers and new versions of service worker) and reported 1626 * through <CODE>attachedToTarget</CODE>. The specified target is also auto-attached. 1627 * This cancels the effect of any previous <CODE>setAutoAttach</CODE> and is also cancelled by subsequent 1628 * <CODE>setAutoAttach</CODE>. Only available at the Browser target. 1629 * <BR /><B>EXPERIMENTAL</B> 1630 * 1631 * @param targetId - 1632 * 1633 * @param waitForDebuggerOnStart 1634 * Whether to pause new targets when attaching to them. Use <CODE>RunTime.runIfWaitingForDebugger</CODE> 1635 * to run paused targets. 1636 * 1637 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1638 * {@link Ret0}></CODE> 1639 * 1640 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1641 * browser receives the invocation-request. 1642 * 1643 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1644 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1645 * {@code >} to ensure the Browser Function has run to completion. 1646 */ 1647 public static Script<String, JsonObject, Ret0> autoAttachRelated 1648 (String targetId, boolean waitForDebuggerOnStart) 1649 { 1650 // Exception-Check(s) to ensure that if any parameters which are not declared as 1651 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1652 1653 if (targetId == null) THROWS.throwNPE("targetId"); 1654 1655 final int webSocketID = 39014000 + counter++; 1656 final boolean[] optionals = { false, false, }; 1657 1658 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1659 String requestJSON = WriteJSON.get( 1660 parameterTypes.get("autoAttachRelated"), 1661 parameterNames.get("autoAttachRelated"), 1662 optionals, webSocketID, 1663 "Target.autoAttachRelated", 1664 targetId, waitForDebuggerOnStart 1665 ); 1666 1667 // This Remote Command does not have a Return-Value. 1668 return new Script<> 1669 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1670 } 1671 1672 /** 1673 * Controls whether to discover available targets and notify via 1674 * <CODE>targetCreated/targetInfoChanged/targetDestroyed</CODE> events. 1675 * 1676 * @param discover Whether to discover available targets. 1677 * 1678 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1679 * {@link Ret0}></CODE> 1680 * 1681 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1682 * browser receives the invocation-request. 1683 * 1684 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1685 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1686 * {@code >} to ensure the Browser Function has run to completion. 1687 */ 1688 public static Script<String, JsonObject, Ret0> setDiscoverTargets(boolean discover) 1689 { 1690 final int webSocketID = 39015000 + counter++; 1691 final boolean[] optionals = { false, }; 1692 1693 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1694 String requestJSON = WriteJSON.get( 1695 parameterTypes.get("setDiscoverTargets"), 1696 parameterNames.get("setDiscoverTargets"), 1697 optionals, webSocketID, 1698 "Target.setDiscoverTargets", 1699 discover 1700 ); 1701 1702 // This Remote Command does not have a Return-Value. 1703 return new Script<> 1704 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1705 } 1706 1707 /** 1708 * Enables target discovery for the specified locations, when <CODE>setDiscoverTargets</CODE> was set to 1709 * <CODE>true</CODE>. 1710 * <BR /><B>EXPERIMENTAL</B> 1711 * 1712 * @param locations List of remote locations. 1713 * 1714 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 1715 * {@link Ret0}></CODE> 1716 * 1717 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 1718 * browser receives the invocation-request. 1719 * 1720 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 1721 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 1722 * {@code >} to ensure the Browser Function has run to completion. 1723 */ 1724 public static Script<String, JsonObject, Ret0> setRemoteLocations 1725 (Target.RemoteLocation[] locations) 1726 { 1727 // Exception-Check(s) to ensure that if any parameters which are not declared as 1728 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 1729 1730 if (locations == null) THROWS.throwNPE("locations"); 1731 1732 final int webSocketID = 39016000 + counter++; 1733 final boolean[] optionals = { false, }; 1734 1735 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 1736 String requestJSON = WriteJSON.get( 1737 parameterTypes.get("setRemoteLocations"), 1738 parameterNames.get("setRemoteLocations"), 1739 optionals, webSocketID, 1740 "Target.setRemoteLocations", 1741 (Object) locations 1742 ); 1743 1744 // This Remote Command does not have a Return-Value. 1745 return new Script<> 1746 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 1747 } 1748 1749}