chore(extension): handle root session id in the relay (#737)
This commit is contained in:
@@ -38,7 +38,6 @@ type ProtocolResponse = {
|
||||
|
||||
export class RelayConnection {
|
||||
private _debuggee: chrome.debugger.Debuggee = {};
|
||||
private _rootSessionId = '';
|
||||
private _ws: WebSocket;
|
||||
private _eventListener: (source: chrome.debugger.DebuggerSession, method: string, params: any) => void;
|
||||
private _detachListener: (source: chrome.debugger.Debuggee, reason: string) => void;
|
||||
@@ -56,11 +55,9 @@ export class RelayConnection {
|
||||
setConnectedTabId(tabId: number | null): void {
|
||||
if (!tabId) {
|
||||
this._debuggee = { };
|
||||
this._rootSessionId = '';
|
||||
return;
|
||||
}
|
||||
this._debuggee = { tabId };
|
||||
this._rootSessionId = `pw-tab-${tabId}`;
|
||||
}
|
||||
|
||||
close(message?: string): void {
|
||||
@@ -77,7 +74,7 @@ export class RelayConnection {
|
||||
if (source.tabId !== this._debuggee.tabId)
|
||||
return;
|
||||
debugLog('Forwarding CDP event:', method, params);
|
||||
const sessionId = source.sessionId || this._rootSessionId;
|
||||
const sessionId = source.sessionId;
|
||||
this._sendMessage({
|
||||
method: 'forwardCDPEvent',
|
||||
params: {
|
||||
@@ -137,7 +134,6 @@ export class RelayConnection {
|
||||
await chrome.debugger.attach(this._debuggee, '1.3');
|
||||
const result: any = await chrome.debugger.sendCommand(this._debuggee, 'Target.getTargetInfo');
|
||||
return {
|
||||
sessionId: this._rootSessionId,
|
||||
targetInfo: result?.targetInfo,
|
||||
};
|
||||
}
|
||||
@@ -148,10 +144,10 @@ export class RelayConnection {
|
||||
if (message.method === 'forwardCDPCommand') {
|
||||
const { sessionId, method, params } = message.params;
|
||||
debugLog('CDP command:', method, params);
|
||||
const debuggerSession: chrome.debugger.DebuggerSession = { ...this._debuggee };
|
||||
// Pass session id, unless it's the root session.
|
||||
if (sessionId && sessionId !== this._rootSessionId)
|
||||
debuggerSession.sessionId = sessionId;
|
||||
const debuggerSession: chrome.debugger.DebuggerSession = {
|
||||
...this._debuggee,
|
||||
sessionId,
|
||||
};
|
||||
// Forward CDP command to chrome.debugger
|
||||
return await chrome.debugger.sendCommand(
|
||||
debuggerSession,
|
||||
|
||||
Reference in New Issue
Block a user