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