076914e5b7
- 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.
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""Session namespace: ``b.session.*``."""
|
|
from __future__ import annotations
|
|
|
|
from browser_cli.sdk.base import Namespace, sdk_command
|
|
|
|
def _load_args(name, gentle_mode, discard_background_tabs, lazy, eager_tabs) -> dict:
|
|
return {
|
|
"name": name,
|
|
"gentleMode": gentle_mode,
|
|
"discardBackgroundTabs": discard_background_tabs,
|
|
"lazy": lazy,
|
|
"eagerTabs": eager_tabs,
|
|
}
|
|
|
|
class SessionNS(Namespace):
|
|
"""Save, restore, list, and diff browser sessions."""
|
|
|
|
@sdk_command("session.save", lambda self, name: {"name": name}, default={})
|
|
def save(self, name: str) -> dict:
|
|
"""Save all current tabs as session *name*. Returns the save result (incl. tab count)."""
|
|
|
|
def load(
|
|
self,
|
|
name: str,
|
|
*,
|
|
gentle_mode: str = "auto",
|
|
discard_background_tabs: bool = False,
|
|
lazy: bool = False,
|
|
eager_tabs: int = 10,
|
|
) -> dict:
|
|
"""Restore session *name*. Returns the load result (incl. tabs opened)."""
|
|
return self.command("session.load", _load_args(name, gentle_mode, discard_background_tabs, lazy, eager_tabs)) or {}
|
|
|
|
def load_background(
|
|
self,
|
|
name: str,
|
|
*,
|
|
gentle_mode: str = "auto",
|
|
discard_background_tabs: bool = False,
|
|
lazy: bool = False,
|
|
eager_tabs: int = 10,
|
|
) -> dict:
|
|
"""Restore session *name* as a background job. Returns the job descriptor."""
|
|
args = _load_args(name, gentle_mode, discard_background_tabs, lazy, eager_tabs)
|
|
return self.command("session.load", {**args, "__background": True}) or {}
|
|
|
|
@sdk_command("session.diff", lambda self, name_a, name_b: {"nameA": name_a, "nameB": name_b}, default={})
|
|
def diff(self, name_a: str, name_b: str) -> dict:
|
|
"""Diff two saved sessions."""
|
|
|
|
def list(self) -> list[dict]:
|
|
"""Return saved sessions.
|
|
|
|
In implicit multi-browser mode each session dict includes a ``browser`` key.
|
|
"""
|
|
return self.multi_list("session.list", {}, self.tag_browser)
|
|
|
|
@sdk_command("session.remove", lambda self, name: {"name": name}, return_result=False)
|
|
def remove(self, name: str) -> None:
|
|
"""Remove a saved session."""
|
|
|
|
@sdk_command("session.auto_save", lambda self, enabled: {"enabled": enabled}, return_result=False)
|
|
def auto_save(self, enabled: bool) -> None:
|
|
"""Enable or disable automatic session saves."""
|