Skip to content

RemoteValue

remote_value

RemoteValue — models for remote values of the BiDi protocol.

RemoteValue

Bases: BaseModel

Base for all remote values of the BiDi protocol.

Source code in bidiwave/protocol/remote_value.py
class RemoteValue(BaseModel):
    """Base for all remote values of the BiDi protocol."""

    model_config = ConfigDict(extra="allow")
    type: str

    @classmethod
    def parse(cls, data: dict[str, Any]) -> RemoteValue:
        """Factory that returns the correct subtype based on type."""
        # script.evaluate/callFunction return {type: "success", result: {...}}
        if data.get("type") == "success":
            if "result" in data:
                data = data["result"]
            else:
                return UndefinedValue.model_validate({"type": "undefined"})
        # JS exception — raise immediately
        if data.get("type") == "exception":
            details = data.get("exceptionDetails", {})
            raise JavaScriptError(
                "javascript error",
                details.get("text", "Unknown JavaScript error"),
            )
        type_name = data.get("type", "")
        match type_name:
            case "string":
                return StringValue.model_validate(data)
            case "number":
                return NumberValue.model_validate(data)
            case "boolean":
                return BooleanValue.model_validate(data)
            case "null":
                return NullValue.model_validate(data)
            case "undefined":
                return UndefinedValue.model_validate(data)
            case "bigint":
                return BigIntValue.model_validate(data)
            case "object":
                return ObjectValue.model_validate(data)
            case "array":
                return ArrayValue.model_validate(data)
            case "symbol" | "function":
                return HandleValue.model_validate(data)
            case "date":
                return DateValue.model_validate(data)
            case "regexp":
                return RegExpValue.model_validate(data)
            case "map":
                return MapValue.model_validate(data)
            case "set":
                return SetValue.model_validate(data)
            case "weakmap":
                return WeakMapValue.model_validate(data)
            case "weakset":
                return WeakSetValue.model_validate(data)
            case "generator":
                return GeneratorValue.model_validate(data)
            case "error":
                return ErrorValue.model_validate(data)
            case "proxy":
                return ProxyValue.model_validate(data)
            case "promise":
                return PromiseValue.model_validate(data)
            case "typedarray":
                return TypedArrayValue.model_validate(data)
            case "arraybuffer":
                return ArrayBufferValue.model_validate(data)
            case "nodelist":
                return NodeListValue.model_validate(data)
            case "htmlcollection":
                return HTMLCollectionValue.model_validate(data)
            case "window":
                return WindowValue.model_validate(data)
            case "node":
                return NodeValue.model_validate(data)
            case "channel":
                return ChannelValue.model_validate(data)
            case _:
                return RemoteValue.model_validate(data)

parse classmethod

parse(data: dict[str, Any]) -> RemoteValue

Factory that returns the correct subtype based on type.

Source code in bidiwave/protocol/remote_value.py
@classmethod
def parse(cls, data: dict[str, Any]) -> RemoteValue:
    """Factory that returns the correct subtype based on type."""
    # script.evaluate/callFunction return {type: "success", result: {...}}
    if data.get("type") == "success":
        if "result" in data:
            data = data["result"]
        else:
            return UndefinedValue.model_validate({"type": "undefined"})
    # JS exception — raise immediately
    if data.get("type") == "exception":
        details = data.get("exceptionDetails", {})
        raise JavaScriptError(
            "javascript error",
            details.get("text", "Unknown JavaScript error"),
        )
    type_name = data.get("type", "")
    match type_name:
        case "string":
            return StringValue.model_validate(data)
        case "number":
            return NumberValue.model_validate(data)
        case "boolean":
            return BooleanValue.model_validate(data)
        case "null":
            return NullValue.model_validate(data)
        case "undefined":
            return UndefinedValue.model_validate(data)
        case "bigint":
            return BigIntValue.model_validate(data)
        case "object":
            return ObjectValue.model_validate(data)
        case "array":
            return ArrayValue.model_validate(data)
        case "symbol" | "function":
            return HandleValue.model_validate(data)
        case "date":
            return DateValue.model_validate(data)
        case "regexp":
            return RegExpValue.model_validate(data)
        case "map":
            return MapValue.model_validate(data)
        case "set":
            return SetValue.model_validate(data)
        case "weakmap":
            return WeakMapValue.model_validate(data)
        case "weakset":
            return WeakSetValue.model_validate(data)
        case "generator":
            return GeneratorValue.model_validate(data)
        case "error":
            return ErrorValue.model_validate(data)
        case "proxy":
            return ProxyValue.model_validate(data)
        case "promise":
            return PromiseValue.model_validate(data)
        case "typedarray":
            return TypedArrayValue.model_validate(data)
        case "arraybuffer":
            return ArrayBufferValue.model_validate(data)
        case "nodelist":
            return NodeListValue.model_validate(data)
        case "htmlcollection":
            return HTMLCollectionValue.model_validate(data)
        case "window":
            return WindowValue.model_validate(data)
        case "node":
            return NodeValue.model_validate(data)
        case "channel":
            return ChannelValue.model_validate(data)
        case _:
            return RemoteValue.model_validate(data)

HandleValue

Bases: RemoteValue

For functions, symbols and objects with circular references.

The handle is only present when the result ownership is "root"; with the default ownership ("none") the browser omits it.

Source code in bidiwave/protocol/remote_value.py
class HandleValue(RemoteValue):
    """For functions, symbols and objects with circular references.

    The handle is only present when the result ownership is "root";
    with the default ownership ("none") the browser omits it.
    """

    type: str
    handle: str | None = None

NodeValue

Bases: RemoteValue

DOM node reference with sharedId.

Source code in bidiwave/protocol/remote_value.py
class NodeValue(RemoteValue):
    """DOM node reference with sharedId."""

    type: Literal["node"] = "node"
    shared_id: str | None = Field(default=None, alias="sharedId")
    value: dict[str, Any] | None = None
    handle: str | None = None
    node_properties: dict[str, Any] | None = Field(
        default=None, alias="nodeProperties"
    )

ChannelValue

Bases: RemoteValue

Channel for preload script communication.

Source code in bidiwave/protocol/remote_value.py
class ChannelValue(RemoteValue):
    """Channel for preload script communication."""

    type: Literal["channel"] = "channel"
    value: dict[str, Any] | None = None
    handle: str | None = None

DateValue

Bases: RemoteValue

JavaScript Date object.

Source code in bidiwave/protocol/remote_value.py
class DateValue(RemoteValue):
    """JavaScript Date object."""

    type: Literal["date"] = "date"
    value: str | None = None
    handle: str | None = None

RegExpValue

Bases: RemoteValue

JavaScript RegExp object.

Source code in bidiwave/protocol/remote_value.py
class RegExpValue(RemoteValue):
    """JavaScript RegExp object."""

    type: Literal["regexp"] = "regexp"
    value: dict[str, Any] | None = None
    handle: str | None = None

MapValue

Bases: RemoteValue

JavaScript Map object — value is list of [key, value] pairs.

Source code in bidiwave/protocol/remote_value.py
class MapValue(RemoteValue):
    """JavaScript Map object — value is list of [key, value] pairs."""

    type: Literal["map"] = "map"
    value: list[list[Any]] | None = None
    handle: str | None = None

SetValue

Bases: RemoteValue

JavaScript Set object — value is list of entries.

Source code in bidiwave/protocol/remote_value.py
class SetValue(RemoteValue):
    """JavaScript Set object — value is list of entries."""

    type: Literal["set"] = "set"
    value: list[Any] | None = None
    handle: str | None = None

WeakMapValue

Bases: RemoteValue

JavaScript WeakMap object — always returned as handle.

Source code in bidiwave/protocol/remote_value.py
class WeakMapValue(RemoteValue):
    """JavaScript WeakMap object — always returned as handle."""

    type: Literal["weakmap"] = "weakmap"
    handle: str | None = None

WeakSetValue

Bases: RemoteValue

JavaScript WeakSet object — always returned as handle.

Source code in bidiwave/protocol/remote_value.py
class WeakSetValue(RemoteValue):
    """JavaScript WeakSet object — always returned as handle."""

    type: Literal["weakset"] = "weakset"
    handle: str | None = None

GeneratorValue

Bases: RemoteValue

JavaScript Generator object — always returned as handle.

Source code in bidiwave/protocol/remote_value.py
class GeneratorValue(RemoteValue):
    """JavaScript Generator object — always returned as handle."""

    type: Literal["generator"] = "generator"
    handle: str | None = None

ErrorValue

Bases: RemoteValue

JavaScript Error object.

Source code in bidiwave/protocol/remote_value.py
class ErrorValue(RemoteValue):
    """JavaScript Error object."""

    type: Literal["error"] = "error"
    value: dict[str, Any] | None = None
    handle: str | None = None

ProxyValue

Bases: RemoteValue

JavaScript Proxy object — always returned as handle.

Source code in bidiwave/protocol/remote_value.py
class ProxyValue(RemoteValue):
    """JavaScript Proxy object — always returned as handle."""

    type: Literal["proxy"] = "proxy"
    handle: str | None = None

PromiseValue

Bases: RemoteValue

JavaScript Promise object — always returned as handle.

Source code in bidiwave/protocol/remote_value.py
class PromiseValue(RemoteValue):
    """JavaScript Promise object — always returned as handle."""

    type: Literal["promise"] = "promise"
    handle: str | None = None

TypedArrayValue

Bases: RemoteValue

JavaScript TypedArray object (Int8Array, Uint8Array, etc.).

Source code in bidiwave/protocol/remote_value.py
class TypedArrayValue(RemoteValue):
    """JavaScript TypedArray object (Int8Array, Uint8Array, etc.)."""

    type: Literal["typedarray"] = "typedarray"
    value: list[Any] | None = None
    handle: str | None = None

ArrayBufferValue

Bases: RemoteValue

JavaScript ArrayBuffer object.

Source code in bidiwave/protocol/remote_value.py
class ArrayBufferValue(RemoteValue):
    """JavaScript ArrayBuffer object."""

    type: Literal["arraybuffer"] = "arraybuffer"
    value: list[Any] | None = None
    handle: str | None = None

NodeListValue

Bases: RemoteValue

DOM NodeList object.

Source code in bidiwave/protocol/remote_value.py
class NodeListValue(RemoteValue):
    """DOM NodeList object."""

    type: Literal["nodelist"] = "nodelist"
    value: list[Any] | None = None
    handle: str | None = None

HTMLCollectionValue

Bases: RemoteValue

DOM HTMLCollection object.

Source code in bidiwave/protocol/remote_value.py
class HTMLCollectionValue(RemoteValue):
    """DOM HTMLCollection object."""

    type: Literal["htmlcollection"] = "htmlcollection"
    value: list[Any] | None = None
    handle: str | None = None

WindowValue

Bases: RemoteValue

Window object — always returned as handle.

Source code in bidiwave/protocol/remote_value.py
class WindowValue(RemoteValue):
    """Window object — always returned as handle."""

    type: Literal["window"] = "window"
    handle: str | None = None
    value: dict[str, Any] | None = None