MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / createTarget

Function createTarget

front_end/testing/TargetHelpers.ts:13–54  ·  view source on GitHub ↗
({
  id,
  name,
  type = SDK.Target.Type.FRAME,
  parentTarget,
  subtype,
  url = 'http://example.com',
  connection,
  targetManager = SDK.TargetManager.TargetManager.instance(),
}: {
  id?: Protocol.Target.TargetID,
  name?: string,
  type?: SDK.Target.Type,
  parentTarget?: SDK.Target.Target,
  subtype?: string,
  url?: string,
  connection?: ProtocolClient.CDPConnection.CDPConnection,
  targetManager?: SDK.TargetManager.TargetManager,
} = {})

Source from the content-addressed store, hash-verified

11let uniqueTargetId = 0;
12
13export function createTarget({
14 id,
15 name,
16 type = SDK.Target.Type.FRAME,
17 parentTarget,
18 subtype,
19 url = 'http://example.com',
20 connection,
21 targetManager = SDK.TargetManager.TargetManager.instance(),
22}: {
23 id?: Protocol.Target.TargetID,
24 name?: string,
25 type?: SDK.Target.Type,
26 parentTarget?: SDK.Target.Target,
27 subtype?: string,
28 url?: string,
29 connection?: ProtocolClient.CDPConnection.CDPConnection,
30 targetManager?: SDK.TargetManager.TargetManager,
31} = {}) {
32 if (!id) {
33 if (!uniqueTargetId++) {
34 id = 'test' as Protocol.Target.TargetID;
35 } else {
36 id = ('test' + uniqueTargetId) as Protocol.Target.TargetID;
37 }
38 }
39 if (!ProtocolClient.ConnectionTransport.ConnectionTransport.getFactory()) {
40 // We are not running with `describeWithMockConnection` so create a fresh mock connection.
41 // Because child targets inherit the SessionRouter/CDPConnection from the parent, we'll throw if a
42 // connection is passed together with a parent target as it would have no effect.
43 if (parentTarget && connection) {
44 throw new Error(
45 'Can\'t create child targets with it\'s own connection. Child targets share the connection with their parent.');
46 }
47 if (!connection && !parentTarget) {
48 connection = new MockCDPConnection([]);
49 }
50 }
51 return targetManager.createTarget(
52 id, name ?? id, type, parentTarget ? parentTarget : null, /* sessionId=*/ parentTarget ? id : undefined,
53 /* suspended=*/ false, connection, {targetId: id, url, subtype} as Protocol.Target.TargetInfo);
54}

Calls 2

instanceMethod · 0.45
createTargetMethod · 0.45

Tested by 6

testNavigationDuringRunFunction · 0.40
setupMockedStyleRulesFunction · 0.40
setupFunction · 0.40