5cec57e06d
Testing / remote-protocol-compat (0.9.3) (push) Successful in 40s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 38s
Testing / test (push) Failing after 1m3s
Package Extension / package-extension (push) Successful in 29s
Build & Publish Package / publish (push) Successful in 33s
- Add safe-by-default policy gates for raw command surfaces: command, script, and serve-http /command. - Require explicit opt-ins for page reads, browser control, and high-risk commands such as dom.eval, storage.*, and screenshots. - Remove all cookies support from CLI, SDK, extension commands, permissions, constants, docs, and tests. - Add diagnostic, events, watch, workspace, remote, raw command, script, HTTP gateway, tree-view, session import/export, and extension info/capability commands. - Add Chrome Web Store packaging that strips manifest.key while keeping local packages with a stable native-messaging extension ID. - Bump browser-cli and extension version to 0.14.1 and cover the new behavior with pytest and extension packaging tests. BREAKING CHANGE: cookies commands and the b.cookies SDK namespace have been removed; generic raw command execution now blocks non-safe commands unless explicitly allowed.
73 lines
2.7 KiB
Python
73 lines
2.7 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."""
|
|
|
|
@sdk_command("session.export", lambda self, name=None: {"name": name}, default={})
|
|
def export(self, name: str | None = None) -> dict:
|
|
"""Export one saved session, or all sessions when *name* is omitted."""
|
|
|
|
@sdk_command("session.import", lambda self, name, session, overwrite=False: {"name": name, "session": session, "overwrite": overwrite}, default={})
|
|
def import_(self, name: str, session: dict, *, overwrite: bool = False) -> dict:
|
|
"""Import a saved session payload under *name*."""
|
|
|
|
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."""
|