diff --git a/src/gateway/server-methods/browser.ts b/src/gateway/server-methods/browser.ts index fb042ad696c..c83ad947570 100644 --- a/src/gateway/server-methods/browser.ts +++ b/src/gateway/server-methods/browser.ts @@ -169,10 +169,12 @@ export const browserHandlers: GatewayRequestHandlers = { allowlist, }); if (!allowed.ok) { + const platform = nodeTarget.platform ?? "unknown"; + const hint = `node command not allowed: ${allowed.reason} (platform: ${platform}, command: browser.proxy)`; respond( false, undefined, - errorShape(ErrorCodes.INVALID_REQUEST, "node command not allowed", { + errorShape(ErrorCodes.INVALID_REQUEST, hint, { details: { reason: allowed.reason, command: "browser.proxy" }, }), ); diff --git a/src/gateway/server-methods/nodes.ts b/src/gateway/server-methods/nodes.ts index 9bb27049685..4f076abd59c 100644 --- a/src/gateway/server-methods/nodes.ts +++ b/src/gateway/server-methods/nodes.ts @@ -687,10 +687,11 @@ export const nodeHandlers: GatewayRequestHandlers = { allowlist, }); if (!allowed.ok) { + const hint = buildNodeCommandRejectionHint(allowed.reason, command, nodeSession); respond( false, undefined, - errorShape(ErrorCodes.INVALID_REQUEST, "node command not allowed", { + errorShape(ErrorCodes.INVALID_REQUEST, hint, { details: { reason: allowed.reason, command }, }), ); @@ -784,3 +785,21 @@ export const nodeHandlers: GatewayRequestHandlers = { }); }, }; + +function buildNodeCommandRejectionHint( + reason: string, + command: string, + node: { platform?: string } | undefined, +): string { + const platform = node?.platform ?? "unknown"; + if (reason === "command not declared by node") { + return `node command not allowed: the node (platform: ${platform}) does not support "${command}"`; + } + if (reason === "command not allowlisted") { + return `node command not allowed: "${command}" is not in the allowlist for platform "${platform}"`; + } + if (reason === "node did not declare commands") { + return `node command not allowed: the node did not declare any supported commands`; + } + return `node command not allowed: ${reason}`; +}