refactor: reorganize client transport and extension internals
- Split client, native, remote, serve, markdown, and SDK internals into focused packages with direct imports. - Move local and remote transport framing/protocol helpers behind clearer module boundaries. - Break up the extension injected DOM logic into a separate content dispatch bundle and dedicated content modules. - Add explicit client handling for passive remote discovery without noisy PQ warnings. - Keep behavior covered with updated unit, integration, and extension tests.
This commit is contained in:
@@ -9,6 +9,11 @@ import type { SessionCommands } from '../commands/session';
|
||||
import type { ControlMessage, ResponseMessage, IncomingMessage, PageRequest, DispatchArgs, Serializable } from '../types';
|
||||
|
||||
const NATIVE_HOST = "com.browsercli.host";
|
||||
const DEBUG_LOG = false;
|
||||
|
||||
function debugLog(...args: Serializable[]) {
|
||||
if (DEBUG_LOG) console.log("[browser-cli]", ...args);
|
||||
}
|
||||
|
||||
export class NativeConnection {
|
||||
private port: chrome.runtime.Port | null = null;
|
||||
@@ -96,7 +101,7 @@ export class NativeConnection {
|
||||
// Send hello so native host knows which profile/alias this is
|
||||
const alias = await getProfileAlias();
|
||||
nativePort.postMessage({ type: "hello", alias });
|
||||
console.log("[browser-cli] Connected to native host as profile:", alias);
|
||||
debugLog("Connected to native host as profile:", alias);
|
||||
} catch (e) {
|
||||
this.port = null;
|
||||
console.error("[browser-cli] Failed to connect:", e);
|
||||
@@ -112,7 +117,7 @@ export class NativeConnection {
|
||||
// on the captured port and bail if it (or this.port) is already gone.
|
||||
const replyPort = this.port;
|
||||
|
||||
console.log("[browser-cli] ←", command, args);
|
||||
debugLog("←", command, args);
|
||||
|
||||
let data: Serializable, error: string | undefined;
|
||||
try {
|
||||
@@ -131,10 +136,10 @@ export class NativeConnection {
|
||||
}
|
||||
|
||||
if (error !== undefined) {
|
||||
console.log("[browser-cli] → ERROR", command, error);
|
||||
debugLog("→ ERROR", command, error);
|
||||
this.sendResponse(replyPort, { id, success: false, error });
|
||||
} else {
|
||||
console.log("[browser-cli] →", command, data);
|
||||
debugLog("→", command, data);
|
||||
this.sendResponse(replyPort, { id, success: true, data });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user