Implementation:MarketSquare Robotframework browser Response Util
| Knowledge Sources | |
|---|---|
| Domains | gRPC, Serialization |
| Last Updated | 2026-02-12 05:40 GMT |
Overview
Concrete tool for constructing typed protobuf gRPC response objects used throughout the playwright-wrapper Node.js server.
Description
The response-util module provides factory functions that create properly typed gRPC response messages for communication between the Node.js Playwright wrapper and the Python Browser library. Each factory function corresponds to a specific protobuf response type (Empty, String, Json, Int, Bool, JavascriptExecutionResult, Keywords, PageReportResponse). The module also includes errorResponse for converting JavaScript exceptions into gRPC error codes and parseRegExpOrKeepString for parsing regex patterns from string input.
Usage
Import these factory functions in any gRPC service handler that needs to return a typed response to the Python side. Every handler in the playwright-wrapper uses these utilities to construct its return values.
Code Reference
Source Location
- Repository: MarketSquare_Robotframework_browser
- File: node/playwright-wrapper/response-util.ts
- Lines: 1-141
Signature
export function emptyWithLog(text: string): Response.Empty;
export function pageReportResponse(log: string, page: IndexedPage): Response.PageReportResponse;
export function getConsoleLogResponse(page: IndexedPage, fullLog: boolean, message: string): Response.Json;
export function getErrorMessagesResponse(page: IndexedPage, fullLog: boolean, message: string): Response.Json;
export function stringResponse(body: string, logMessage: string): Response.String;
export function jsonResponse(body: string, logMessage: string, bodyPart?: string): Response.Json;
export function intResponse(body: number, logMessage: string): Response.Int;
export function boolResponse(value: boolean, logMessage: string): Response.Bool;
export function jsResponse(result: string, logMessage: string): Response.JavascriptExecutionResult;
export function errorResponse(e: unknown): { code: status; message: string } | null;
export function keywordsResponse(keywords: string[], keywordArguments: string[], keywordDocs: string[], logMessage: string): Response.Keywords;
export function parseRegExpOrKeepString(str: string): RegExp | string;
Import
import { emptyWithLog, stringResponse, jsonResponse, errorResponse } from './response-util';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| text/body/log | string | Yes | The content or log message to embed in the response |
| page | IndexedPage | Conditional | Required for pageReportResponse, getConsoleLogResponse, getErrorMessagesResponse |
| fullLog | boolean | Conditional | Whether to return all messages or only new ones since last call |
| e | unknown | Conditional | Exception object for errorResponse |
Outputs
| Name | Type | Description |
|---|---|---|
| Response.Empty | protobuf message | Empty response with log text |
| Response.String | protobuf message | String body with log |
| Response.Json | protobuf message | JSON body with log and optional body part |
| Response.Int | protobuf message | Integer body with log |
| Response.Bool | protobuf message | Boolean body with log |
| Response.JavascriptExecutionResult | protobuf message | JS execution result with log |
| Response.Keywords | protobuf message | Keyword list with docs and arguments |
| Response.PageReportResponse | protobuf message | Page report with console messages and errors |
Usage Examples
import { stringResponse, emptyWithLog, errorResponse } from './response-util';
// Return a string response from a gRPC handler
export async function goTo(request: Request.UrlOptions, page: Page): Promise<Response.Empty> {
await page.goto(request.getUrl());
return emptyWithLog(`Navigated to ${request.getUrl()}`);
}
// Return a file path response
export async function savePageAsPdf(request: Request.Pdf, state: PlaywrightState): Promise<Response.String> {
const pdfPath = request.getPath();
await activePage.pdf({ path: pdfPath });
return stringResponse(pdfPath, `Pdf is saved to ${pdfPath}`);
}
// Handle errors in gRPC handlers
try {
// ... handler logic
} catch (e) {
const error = errorResponse(e);
if (error) callback(error);
}