Skip to content

Commit a745b09

Browse files
committed
feat: allow set $0 on created and toggle sync
1 parent 1ee09fc commit a745b09

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/Inspector.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export type CDPClient = {
3333
export type InspectorOptions = {
3434
documentImpl?: DOMImplementation;
3535
eventTimeout?: number;
36+
selectedNodeXPath?: string;
37+
sync$0Enabled?: boolean;
3638
};
3739

3840
export type MatchedStylesOptions = {
@@ -54,6 +56,8 @@ export class Inspector extends EventEmitter {
5456

5557
protected selectedNode: InspectorNode | undefined;
5658

59+
protected sync$0Enabled: boolean = true;
60+
5761
get document(): InspectorDocument {
5862
return InspectorDocument.get(this.RootDocument);
5963
}
@@ -68,6 +72,14 @@ export class Inspector extends EventEmitter {
6872
return undefined;
6973
}
7074

75+
setSelectedNodeByXPath(xpath: string): void {
76+
this.selectedNode = this.queryXPath(xpath) || undefined;
77+
}
78+
79+
toggleSync$0(enable: boolean): void {
80+
this.sync$0Enabled = enable;
81+
}
82+
7183
/* legacy forwardings */
7284

7385
querySelector(selector: string): InspectorElement | null {
@@ -149,6 +161,9 @@ export class Inspector extends EventEmitter {
149161
);
150162
}
151163
this.eventTimeout = options.eventTimeout || 100;
164+
if (options.sync$0Enabled === false) {
165+
this.sync$0Enabled = false;
166+
}
152167
}
153168

154169
// factory methods
@@ -167,6 +182,9 @@ export class Inspector extends EventEmitter {
167182
const inspector = new Inspector(sendCommand, onCDP, offCDP, options);
168183
await inspector.init();
169184
await inspector.initDOM();
185+
if (options.selectedNodeXPath) {
186+
inspector.setSelectedNodeByXPath(options.selectedNodeXPath);
187+
}
170188
return inspector;
171189
}
172190

@@ -459,7 +477,7 @@ export class Inspector extends EventEmitter {
459477
this.onCDP(
460478
"Runtime.bindingCalled",
461479
(params: { name: string; payload: string }) => {
462-
this.selectedNode = this.queryXPath(params.payload) || undefined;
480+
if (this.sync$0Enabled) this.setSelectedNodeByXPath(params.payload);
463481
},
464482
);
465483
}

0 commit comments

Comments
 (0)