### Basic Geckordp Usage Example Source: https://github.com/jpramosi/geckordp/blob/master/docs/index.html A Python script demonstrating how to start Firefox, connect using RDPClient, and list tabs. ```python import json from geckordp.actors.root import RootActor from geckordp.firefox import Firefox from geckordp.profile import ProfileManager from geckordp.rdp_client import RDPClient """ Uncomment to enable debug output """ # from geckordp.settings import GECKORDP # GECKORDP.DEBUG = 1 # GECKORDP.DEBUG_REQUEST = 1 # GECKORDP.DEBUG_RESPONSE = 1 def main(): # clone default profile to 'geckordp' pm = ProfileManager() profile_name = "geckordp" port = 6000 pm.clone("default-release", profile_name) profile = pm.get_profile_by_name(profile_name) profile.set_required_configs() # start firefox with specified profile Firefox.start("https://example.com/", port, profile_name, ["-headless"]) # create client and connect to firefox client = RDPClient() client.connect("localhost", port) # initialize root root = RootActor(client) # get a list of tabs tabs = root.list_tabs() print(json.dumps(tabs, indent=2)) input() if __name__ == "__main__": main() ``` -------------------------------- ### Run geckordp Example Usage Source: https://github.com/jpramosi/geckordp/blob/master/README.md A Python script demonstrating how to use geckordp to start Firefox, connect to the debug server, and list available tabs. ```python import json from geckordp.actors.root import RootActor from geckordp.firefox import Firefox from geckordp.profile import ProfileManager from geckordp.rdp_client import RDPClient """ Uncomment to enable debug output """ # from geckordp.settings import GECKORDP # GECKORDP.DEBUG = 1 # GECKORDP.DEBUG_REQUEST = 1 # GECKORDP.DEBUG_RESPONSE = 1 def main(): # clone default profile to 'geckordp' pm = ProfileManager() profile_name = "geckordp" port = 6000 pm.clone("default-release", profile_name) profile = pm.get_profile_by_name(profile_name) profile.set_required_configs() # start firefox with specified profile Firefox.start("https://example.com/", port, profile_name, ["-headless"]) # create client and connect to firefox client = RDPClient() client.connect("localhost", port) # initialize root root = RootActor(client) # get a list of tabs tabs = root.list_tabs() print(json.dumps(tabs, indent=2)) input() if __name__ == "__main__": main() ``` -------------------------------- ### Basic geckordp Usage Example Source: https://github.com/jpramosi/geckordp/blob/master/docs/pypi/README.md Demonstrates the basic usage of geckordp to connect to a running Firefox instance, list available tabs, and print them as JSON. It involves setting up a profile, starting Firefox, and establishing an RDP client connection. ```python import json from geckordp.actors.root import RootActor from geckordp.firefox import Firefox from geckordp.profile import ProfileManager from geckordp.rdp_client import RDPClient """ Uncomment to enable debug output """ # from geckordp.settings import GECKORDP # GECKORDP.DEBUG = 1 # GECKORDP.DEBUG_REQUEST = 1 # GECKORDP.DEBUG_RESPONSE = 1 def main(): # clone default profile to 'geckordp' pm = ProfileManager() profile_name = "geckordp" port = 6000 pm.clone("default-release", profile_name) profile = pm.get_profile_by_name(profile_name) profile.set_required_configs() # start firefox with specified profile Firefox.start("https://example.com/", port, profile_name, ["-headless"]) # create client and connect to firefox client = RDPClient() client.connect("localhost", port) # initialize root root = RootActor(client) # get a list of tabs tabs = root.list_tabs() print(json.dumps(tabs, indent=2)) input() if __name__ == "__main__": main() ``` -------------------------------- ### Install Geckordp with Venv Source: https://github.com/jpramosi/geckordp/blob/master/docs/index.html Demonstrates how to install geckordp within a Python virtual environment using venv. ```bash python -m venv .venv source .venv/bin/activate python -m pip install --upgrade geckordp ``` -------------------------------- ### Control Firefox Instances with Firefox Class Source: https://context7.com/jpramosi/geckordp/llms.txt Shows how to use the Firefox class to manage browser instances, including getting binary paths, profile directories, and starting Firefox with specific configurations like custom URLs, ports, profiles, and command-line arguments. It also covers automatic process killing and waiting for the browser to load. ```python from geckordp.firefox import Firefox import subprocess # Get Firefox binary path (platform-dependent) binary_path = Firefox.get_binary_path() print(f"Firefox binary: {binary_path}") # Get profiles directory profiles_path = Firefox.get_profiles_path() print(f"Profiles at: {profiles_path}") # Start Firefox with debug server proc: subprocess.Popen = Firefox.start( url="https://example.com/", port=6000, profile="geckordp", append_args=["-headless"], # Additional CLI arguments auto_kill=True, # Kill Firefox when Python exits wait=True # Wait for Firefox to fully load ) # Process handle can be used for manual control print(f"Firefox PID: {proc.pid}") ``` -------------------------------- ### Install geckordp Python Package Source: https://github.com/jpramosi/geckordp/blob/master/README.md Instructions for installing the geckordp library using pip, including options for development dependencies and virtual environment setup. ```bash pip install --upgrade geckordp # python -m pip install --upgrade geckordp # python -m pip install --upgrade geckordp[develop] ``` ```bash python -m venv .venv source .venv/bin/activate python -m pip install --upgrade geckordp ``` -------------------------------- ### POST /start_recording_allocations Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.memory.html Starts the recording of memory allocations with optional configuration parameters. ```APIDOC ## POST /start_recording_allocations ### Description Begins tracking memory allocations. This allows developers to monitor how memory is being consumed over a specific period. ### Method POST ### Endpoint /start_recording_allocations ### Parameters #### Request Body - **probability** (float) - Optional - Sampling probability for allocations. - **max_log_length** (int) - Optional - Maximum number of entries in the allocation log. ### Request Example { "probability": 0.1, "max_log_length": 1000 } ### Response #### Success Response (200) - **status** (string) - Confirmation that recording has started. #### Response Example { "status": "recording_started" } ``` -------------------------------- ### Initialize and Start Performance Recording Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.performance.html Demonstrates how to instantiate the PerformanceActor and initiate a new recording session with custom profiling parameters. ```python from geckordp.actors.performance import PerformanceActor # Assuming actor is initialized with a valid RDP connection perf_actor = PerformanceActor(*args, **kwargs) perf_actor.connect() # Start recording with specific markers and memory tracking perf_actor.start_recording( with_markers=True, with_memory=True, sample_frequency=1000 ) ``` -------------------------------- ### Manage Firefox Paths and Launching Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.firefox.html Demonstrates how to retrieve system paths for the Firefox binary and profiles, and how to programmatically start a Firefox instance with specific debugging parameters. ```python from geckordp.firefox import Firefox # Retrieve system paths binary_path = Firefox.get_binary_path() profiles_path = Firefox.get_profiles_path() # Start a Firefox instance with RDP enabled process = Firefox.start( url="https://example.com/", port=6000, profile="geckordp", auto_kill=True, wait=True ) ``` -------------------------------- ### Start Allocation Recording with MemoryActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.memory.html Configures and starts the recording of memory allocations. It accepts optional probability and log length parameters to control the granularity of the data. ```python memory_actor.start_recording_allocations(probability=0.1, max_log_length=1000) ``` -------------------------------- ### POST /memory/start_recording_allocations Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.memory.html Starts tracking memory allocations within the browser process. ```APIDOC ## POST /memory/start_recording_allocations ### Description Begins recording memory allocation events with specified probability and log length constraints. ### Method POST ### Endpoint /memory/start_recording_allocations ### Parameters #### Request Body - **probability** (float) - Optional - The sampling probability for allocations. - **max_log_length** (int) - Optional - The maximum number of events to store in the log. ### Request Example { "probability": 0.1, "max_log_length": 1000 } ### Response #### Success Response (200) - **status** (string) - Confirmation that allocation recording has started. #### Response Example { "status": "recording_started" } ``` -------------------------------- ### Browser Process and Addon Listing Source: https://context7.com/jpramosi/geckordp/llms.txt Demonstrates how to list browser processes and installed addons using the root actor. ```APIDOC ## List browser processes and addons ### Description This snippet shows how to list all running browser processes and installed addons using the root actor. ### Method N/A (Scripted) ### Endpoint N/A (Scripted) ### Parameters None ### Request Example ```python from geckordp.actors.root import RootActor from geckordp.rdp_client import RDPClient client = RDPClient() client.connect("localhost", 6000) root = RootActor(client) # List processes processes = root.list_processes() for proc in processes: print(f"Process: {proc['actor']}, Parent: {proc['isParent']}") # List addons addons = root.list_addons() for addon in addons: print(f"Addon: {addon.get('name', 'Unknown')}") # List workers workers = root.list_workers() print(json.dumps(workers, indent=2)) ``` ### Response Output will be printed to the console, showing process information, addon names, and worker details. ``` -------------------------------- ### Install Geckordp with Pip Source: https://github.com/jpramosi/geckordp/blob/master/docs/index.html Instructions for installing the geckordp package using pip, including options for development dependencies. ```bash pip install --upgrade geckordp # python -m pip install --upgrade geckordp # python -m pip install --upgrade geckordp[develop] ``` -------------------------------- ### Install Temporary Addon using AddonsActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.addon.addons.html This method allows for the temporary installation of an addon from a specified file path. It is typically used for automated testing or development workflows where addons need to be loaded dynamically. ```python from geckordp.actors.addon.addons import AddonsActor # Assuming actor is initialized via RDP client addons_actor = AddonsActor(client) addons_actor.install_temporary_addon("/path/to/addon.xpi") ``` -------------------------------- ### Install Geckordp Python Package Source: https://context7.com/jpramosi/geckordp/llms.txt Installs the geckordp library using pip. Requires Python 3.10+ and a recent Firefox installation. ```bash pip install --upgrade geckordp ``` -------------------------------- ### GET /root/processes Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.html Lists all active browser processes. ```APIDOC ## GET /root/list_processes ### Description Returns a list of all processes currently running within the browser environment. ### Method GET ### Endpoint /root/list_processes ### Response #### Success Response (200) - **processes** (array) - List of process objects. #### Response Example { "processes": [ { "id": 1234, "name": "Web Content" } ] } ``` -------------------------------- ### POST /addons/install_temporary_addon Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/addon.addons.html Installs a temporary addon into the Firefox instance using the provided file path. ```APIDOC ## POST /addons/install_temporary_addon ### Description Installs an addon temporarily in the target Firefox instance. This is typically used for testing and development purposes. ### Method POST ### Endpoint /addons/install_temporary_addon ### Parameters #### Request Body - **addon_path** (string) - Required - The absolute file system path to the .xpi or directory of the addon to be installed. ### Request Example { "addon_path": "/path/to/your/extension.xpi" } ### Response #### Success Response (200) - **status** (string) - Indicates the success of the installation process. #### Response Example { "status": "success" } ``` -------------------------------- ### POST /actors/addon/addons/install_temporary_addon Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.addon.html Installs a temporary addon into the browser instance via the AddonsActor. ```APIDOC ## POST /actors/addon/addons/install_temporary_addon ### Description Installs a temporary addon from a specified path or file into the browser session. ### Method POST ### Endpoint /actors/addon/addons/install_temporary_addon ### Parameters #### Request Body - **path** (string) - Required - The file system path to the addon file or directory. ### Request Example { "path": "/path/to/addon.xpi" } ### Response #### Success Response (200) - **addonId** (string) - The unique identifier of the installed addon. #### Response Example { "addonId": "addon-12345@example.com" } ``` -------------------------------- ### POST /addons/install_temporary_addon Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.addon.addons.html Installs a temporary addon into the target Firefox instance using the provided file path. ```APIDOC ## POST /addons/install_temporary_addon ### Description Installs a temporary addon from a local file path into the browser session. ### Method POST ### Endpoint /addons/install_temporary_addon ### Parameters #### Request Body - **addon_path** (string) - Required - The absolute file path to the addon (.xpi or directory) to be installed. ### Request Example { "addon_path": "/path/to/extension.xpi" } ### Response #### Success Response (200) - **status** (string) - Indicates the success status of the installation. #### Response Example { "status": "success" } ``` -------------------------------- ### Start Web Console Listeners Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.web_console.html Starts listening for specified events on the web console actor. It accepts a list of Listener types, such as ConsoleAPI or PageError, to begin receiving event notifications. ```python def start_listeners(self, listeners: List[Listeners]): """Start listening for web console events.""" pass ``` -------------------------------- ### Connect to Firefox Debugging Server with RDPClient Source: https://context7.com/jpramosi/geckordp/llms.txt Demonstrates setting up a Firefox profile, starting Firefox with remote debugging enabled, and establishing a connection to the debug server using RDPClient. It shows both direct connection and usage with a context manager for automatic cleanup. ```python from geckordp.rdp_client import RDPClient from geckordp.profile import ProfileManager from geckordp.firefox import Firefox # Setup profile with required configurations pm = ProfileManager() profile_name = "geckordp" pm.clone("default-release", profile_name) profile = pm.get_profile_by_name(profile_name) profile.set_required_configs() # Start Firefox with remote debugging enabled Firefox.start("https://example.com/", 6000, profile_name, ["-headless"]) # Connect to Firefox debug server client = RDPClient(timeout_sec=3.0, max_buffer_size=33554432) response = client.connect("localhost", 6000) print(f"Connected: {client.connected()}") # Use context manager for automatic cleanup with RDPClient() as client: client.connect("localhost", 6000) # ... perform operations # Connection automatically closed on exit ``` -------------------------------- ### GET /actors/preference/get_all_prefs Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Retrieves all preferences from the PreferenceActor. ```APIDOC ## GET /actors/preference/get_all_prefs ### Description Retrieves a complete list of all preferences currently managed by the PreferenceActor. ### Method GET ### Endpoint /actors/preference/get_all_prefs ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **preferences** (object) - A dictionary containing all preference keys and their values. #### Response Example { "preferences": { "browser.startup.homepage": "about:home", "javascript.enabled": true } } ``` -------------------------------- ### Run geckordp Tests Source: https://github.com/jpramosi/geckordp/blob/master/README.md Instructions to clone the geckordp repository, set up a virtual environment, install the package in editable mode, and run the test suite. ```bash cd git clone https://github.com/jpramosi/geckordp cd geckordp python -m venv .venv source .venv/bin/activate python -m pip install -e $PWD pytest tests/ &> test.log ``` -------------------------------- ### Initialize InspectorActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.inspector.html Example of how to instantiate the InspectorActor class to begin interacting with the inspector actor on a remote Firefox instance. ```python from geckordp.actors.inspector import InspectorActor # Assuming an established RDP connection inspector = InspectorActor(*args, **kwargs) walker = inspector.get_walker() ``` -------------------------------- ### Automate Web Scraping with Geckordp Source: https://context7.com/jpramosi/geckordp/llms.txt This example demonstrates how to initialize a headless Firefox instance, connect via RDP, execute JavaScript in the browser context, and extract DOM information using the Inspector and Walker actors. ```python import json from geckordp.actors.root import RootActor from geckordp.actors.descriptors.tab import TabActor from geckordp.actors.web_console import WebConsoleActor from geckordp.actors.inspector import InspectorActor from geckordp.actors.walker import WalkerActor from geckordp.firefox import Firefox from geckordp.profile import ProfileManager from geckordp.rdp_client import RDPClient def scrape_website(url: str) -> dict: pm = ProfileManager() profile_name = "scraper" pm.clone("default-release", profile_name) profile = pm.get_profile_by_name(profile_name) profile.set_required_configs() port = 6000 Firefox.start(url, port, profile_name, ["-headless"]) client = RDPClient() client.connect("localhost", port) root = RootActor(client) tab = TabActor(client, root.list_tabs()[0]["actor"]) target = tab.get_target() console = WebConsoleActor(client, target["consoleActor"]) console.start_listeners([]) result = {} response = console.evaluate_js_async(""" (() => { return { title: document.title, url: window.location.href, links: Array.from(document.querySelectorAll('a')) .map(a => ({text: a.textContent.trim(), href: a.href})) .filter(l => l.href && l.text) }; })(); """) inspector = InspectorActor(client, target["inspectorActor"]) walker_ctx = inspector.get_walker() walker = WalkerActor(client, walker_ctx["actor"]) document = walker.document() body = walker.query_selector(document["actor"], "body") if body.get("node"): html = walker.outer_html(body["node"]["actor"]) result["html_length"] = len(html) headings = [] for tag in ["h1", "h2", "h3"]: elements = walker.query_selector_all(document["actor"], tag) for elem in elements.get("nodes", []): inner = walker.inner_html(elem["actor"]) headings.append({"tag": tag, "text": inner.strip()}) result["headings"] = headings client.disconnect() return result data = scrape_website("https://example.com/") print(json.dumps(data, indent=2)) ``` -------------------------------- ### GET /actors/root/current_tab Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Retrieves the currently active tab from the RootActor. ```APIDOC ## GET /actors/root/current_tab ### Description Fetches the identifier for the current active tab in the browser session. ### Method GET ### Endpoint /actors/root/current_tab ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **tab_id** (string) - The unique identifier of the current tab. #### Response Example { "tab_id": "tab-123" } ``` -------------------------------- ### GET /actors/memory/get_allocations Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Retrieves memory allocation data from the MemoryActor. ```APIDOC ## GET /actors/memory/get_allocations ### Description Fetches current memory allocation records from the MemoryActor to assist in profiling and debugging memory usage. ### Method GET ### Endpoint /actors/memory/get_allocations ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **allocations** (array) - A list of memory allocation objects. #### Response Example { "allocations": [ {"size": 1024, "type": "ArrayBuffer"}, {"size": 512, "type": "String"} ] } ``` -------------------------------- ### GET /actors/preference/get_int_pref Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Retrieves an integer preference value from the browser configuration. ```APIDOC ## GET /actors/preference/get_int_pref ### Description Fetches the integer value of a specific browser preference. ### Method GET ### Endpoint /actors/preference/get_int_pref ### Parameters #### Query Parameters - **pref_name** (string) - Required - The name of the preference to retrieve. ### Request Example { "pref_name": "browser.tabs.remote.autostart" } ### Response #### Success Response (200) - **value** (integer) - The integer value of the preference. #### Response Example { "value": 1 } ``` -------------------------------- ### Run Geckordp Test Suite Source: https://github.com/jpramosi/geckordp/blob/master/tests/README.md This sequence of commands clones the repository, installs the package in editable mode, and executes the test suite using pytest. The output is redirected to a log file for review. ```bash cd git clone https://github.com/jpramosi/geckordp cd geckordp python -m pip uninstall geckordp python -m pip install -e $PWD pytest tests/ &> test.log ``` -------------------------------- ### List Browser Processes, Addons, and Workers Source: https://context7.com/jpramosi/geckordp/llms.txt This snippet demonstrates how to list all running browser processes, installed addons, and active workers (service workers, shared workers) using the RootActor. It iterates through the results and prints relevant information. ```python processes = root.list_processes() for proc in processes: print(f"Process: {proc['actor']}, Parent: {proc['isParent']}") addons = root.list_addons() for addon in addons: print(f"Addon: {addon.get('name', 'Unknown')}") workers = root.list_workers() print(json.dumps(workers, indent=2)) ``` -------------------------------- ### GET /actors/events/webconsole/file_activity Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Retrieves the file activity listener status from the WebConsole actor. ```APIDOC ## GET /actors/events/webconsole/file_activity ### Description Returns the current status or definition of the FILE_ACTIVITY event listener within the WebConsole actor. ### Method GET ### Endpoint /actors/events/webconsole/file_activity ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **status** (string) - The current state of the file activity listener. #### Response Example { "status": "active" } ``` -------------------------------- ### GET /actors/string/substring Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.string.html Retrieves a substring from a string actor instance using defined start and end indices. ```APIDOC ## GET /actors/string/substring ### Description Extracts a portion of a string managed by the StringActor. ### Method GET ### Endpoint /actors/string/substring ### Parameters #### Query Parameters - **start** (int) - Required - The starting index of the substring. - **end** (int) - Required - The ending index of the substring. ### Request Example { "start": 0, "end": 5 } ### Response #### Success Response (200) - **substring** (string) - The extracted portion of the string. #### Response Example { "substring": "Hello" } ``` -------------------------------- ### Control Web Console Listeners Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/web_console.html Functions to start and stop listeners for web console events. Requires a list of `WebConsoleActor.Listeners` as input. ```python start_listeners(_listeners: List[web_console.WebConsoleActor.Listeners]) stop_listeners(_listeners: List[web_console.WebConsoleActor.Listeners]) ``` -------------------------------- ### Initialize ResourceActor and Watch Resources Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.resources.html Demonstrates how to instantiate the ResourceActor and use the watch_resources method to begin tracking specific resource types. ```python from geckordp.actors.resources import ResourceActor, Resources # Assuming rdp_client is already initialized resource_actor = ResourceActor(rdp_client, actor_id="resourceActorId") # Watch for console messages and network events resource_actor.watch_resources([Resources.CONSOLE_MESSAGE, Resources.NETWORK_EVENT]) ``` -------------------------------- ### GET /utils/find_free_ports Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Utility endpoint to discover available network ports for debugger connections. ```APIDOC ## GET /utils/find_free_ports ### Description Scans the local system for available network ports that can be used for geckordp debugger instances. ### Method GET ### Endpoint /utils/find_free_ports ### Parameters #### Query Parameters - **count** (integer) - Optional - Number of ports to find. ### Request Example {} ### Response #### Success Response (200) - **ports** (array) - List of available port numbers. #### Response Example { "ports": [9222, 9223, 9224] } ``` -------------------------------- ### GET /actors/walker/get_node_value Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Retrieves the value of a specific DOM node using the NodeActor. ```APIDOC ## GET /actors/walker/get_node_value ### Description Retrieves the text or value content of a specified DOM node. ### Method GET ### Endpoint /actors/node/get_node_value ### Parameters #### Query Parameters - **node_actor** (string) - Required - The actor ID of the node to query. ### Request Example { "node_actor": "node-123" } ### Response #### Success Response (200) - **value** (string) - The content of the node. #### Response Example { "value": "Hello World" } ``` -------------------------------- ### Initialize and Use WindowGlobalActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.targets.window_global.html Demonstrates how to instantiate the WindowGlobalActor and perform basic navigation and frame listing operations. ```python from geckordp.actors.targets.window_global import WindowGlobalActor # Assuming actor is initialized via a connection actor = WindowGlobalActor(*args, **kwargs) # Navigate to a URL actor.navigate_to("https://www.mozilla.org") # List available frames frames = actor.list_frames() # Reload the current page actor.reload() ``` -------------------------------- ### Initialize and Use WindowGlobalActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/targets.window_global.html Demonstrates how to instantiate the WindowGlobalActor and utilize its primary navigation and control methods such as navigate_to, reload, and frame switching. ```python from geckordp.actors.targets.window_global import WindowGlobalActor # Assuming actor is initialized via RDP client actor = WindowGlobalActor(*args, **kwargs) # Navigate to a URL actor.navigate_to("https://example.com") # Perform browser actions actor.reload() actor.go_back() actor.go_forward() # Manage frames frames = actor.list_frames() actor.switch_to_frame("frame_id_here") ``` -------------------------------- ### Memory Profiling with MemoryActor Source: https://context7.com/jpramosi/geckordp/llms.txt Demonstrates how to use the MemoryActor for memory profiling, allocation tracking, and heap snapshots. It covers attaching and detaching the actor, getting memory state, measuring usage, recording allocations, and forcing garbage collection. ```python from geckordp.actors.memory import MemoryActor from geckordp.actors.heap_snapshot import HeapSnapshotActor from geckordp.actors.descriptors.tab import TabActor from geckordp.actors.root import RootActor from geckordp.rdp_client import RDPClient client = RDPClient() client.connect("localhost", 6000) root = RootActor(client) root_ids = root.get_root() tab = TabActor(client, root.list_tabs()[0]["actor"]) target = tab.get_target() memory = MemoryActor(client, target["memoryActor"]) # Attach memory actor memory.attach() # Get current memory state state = memory.get_state() print(f"Memory state: {state}") # Measure memory usage measurement = memory.measure() print(f"Memory measurement: {measurement}") # Get resident unique memory resident = memory.resident_unique() print(f"Resident unique: {resident}") # Start recording allocations memory.start_recording_allocations( probability=1.0, # Sample 100% of allocations max_log_length=5000 # Maximum log entries ) # Get allocations allocations = memory.get_allocations() print(f"Allocations: {allocations}") # Stop recording memory.stop_recording_allocations() # Force garbage collection memory.force_garbage_collection() # Force cycle collection memory.force_cycle_collection() # Take a heap snapshot snapshot_id = memory.save_heap_snapshot() print(f"Heap snapshot ID: {snapshot_id}") # Use HeapSnapshotActor for snapshot operations heap_actor = HeapSnapshotActor(client, root_ids["heapSnapshotFileActor"]) # Detach memory actor memory.detach() ``` -------------------------------- ### Initialize and Use SourceActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.source.html Demonstrates how to instantiate the SourceActor and utilize its core debugging methods like blackboxing and setting pause points. ```python from geckordp.actors.source import SourceActor # Initialize actor source_actor = SourceActor(client, "sourceActorId") # Blackbox a range of lines source_actor.blackbox(10, 0, 20, 0) # Set a pause point source_actor.set_pause_point(15, 5, breakpoint_=True, stepover=True) # Get breakable lines lines = source_actor.get_breakable_lines() ``` -------------------------------- ### Initialize and Use TabActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.descriptors.tab.html Demonstrates how to instantiate a TabActor and utilize its primary methods to retrieve tab metadata and watcher configurations. ```python from geckordp.actors.descriptors.tab import TabActor # Assuming an existing RDP client connection tab_actor = TabActor(client, actor_id="tabActor1") # Retrieve tab favicon favicon = tab_actor.get_favicon() # Retrieve target information target = tab_actor.get_target() # Retrieve watcher with specific configuration watcher = tab_actor.get_watcher(is_server_target_switching_enabled=True, is_popup_debugging_enabled=False) ``` -------------------------------- ### Interact with Browser using RootActor Source: https://context7.com/jpramosi/geckordp/llms.txt Demonstrates how to use the RootActor to perform browser-level operations. This includes fetching root actor IDs, listing all open tabs, getting the currently selected tab, and retrieving a specific tab by its browser ID. ```python import json from geckordp.actors.root import RootActor from geckordp.rdp_client import RDPClient client = RDPClient() client.connect("localhost", 6000) root = RootActor(client) # Get root actor IDs for other actors root_ids = root.get_root() print(f"Device Actor: {root_ids['deviceActor']}") print(f"Screenshot Actor: {root_ids['screenshotActor']}") # List all open tabs tabs = root.list_tabs() for tab in tabs: print(f"Tab: {tab['title']} - {tab['url']}") # Get the currently selected tab current_tab = root.current_tab() print(f"Current tab: {current_tab['title']}") # Get a specific tab by browser ID tab = root.get_tab(browser_id=tabs[0]["browserId"]) ``` -------------------------------- ### Initialize and Use NetworkContentActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/network_content.html Demonstrates how to instantiate the NetworkContentActor and utilize its primary methods for network interaction, including fetching stack traces and executing HTTP requests. ```python from geckordp.actors.network_content import NetworkContentActor # Initialize the actor actor = NetworkContentActor(*args, **kwargs) # Retrieve stack trace for a specific resource ID stack_trace = actor.get_stack_trace(resource_id=123) # Send a custom HTTP request response = actor.send_http_request(method="GET", url="https://example.com", headers={"Content-Type": "application/json"}) ``` -------------------------------- ### Get Preference Values (Python) Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.preference.html Retrieves the value of a specified preference. Supports boolean, character, and integer types. It takes no arguments for get_traits() and expects a name for other get functions. ```python get_bool_pref(_value: Any_) get_char_pref(_value: Any_) get_int_pref(_value: Any_) get_traits() ``` -------------------------------- ### Initialize and Control WebSocketActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/web_socket.html Demonstrates how to instantiate the WebSocketActor and utilize its control methods to manage event listening states. ```python from geckordp.actors.web_socket import WebSocketActor # Initialize the actor ws_actor = WebSocketActor(*args, **kwargs) # Start listening for WebSocket events ws_actor.start_listening() # Stop listening for WebSocket events ws_actor.stop_listening() ``` -------------------------------- ### Initialize and Use RootActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.root.html Demonstrates how to instantiate the RootActor and access its primary methods for querying browser state, such as listing tabs and processes. ```python from geckordp.actors.root import RootActor # Assuming an active RDP connection root = RootActor(client) # List all open tabs tabs = root.list_tabs() # Get a specific process by PID process = root.get_process(1234) ``` -------------------------------- ### GET /children Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.walker.html Retrieves the children of a specified DOM node. ```APIDOC ## GET /children ### Description Fetches the child nodes for a given DOM node actor with optional pagination and filtering. ### Method GET ### Endpoint /children ### Parameters #### Query Parameters - **dom_node_actor** (str) - Required - The actor ID of the parent node. - **max_nodes** (int) - Optional - Maximum number of nodes to return (default: 1000). ### Response #### Success Response (200) - **nodes** (array) - List of child node actor objects. ``` -------------------------------- ### Initialize Storage Actors via Resource Watching Source: https://github.com/jpramosi/geckordp/blob/master/docs/examples/actor_initialization.html Demonstrates how to watch for specific resources (IndexedDB, LocalStorage, SessionStorage) using a WatcherActor and initialize the corresponding storage actors upon receiving the resource event. ```python async def on_indexed_resource(data: dict): array = data.get("array", []) for sub_array in array: for i, item in enumerate(sub_array): if isinstance(item, str) and "indexed-db" in item: for obj in sub_array[i + 1]: if "indexedDB" in obj.get("actor", ""): try: indexed_fut.set_result(obj) except: pass break client.add_event_listener(WATCHER.actor_id, Events.Watcher.RESOURCES_AVAILABLE_ARRAY, on_indexed_resource) WATCHER.watch_resources([Resources.INDEXED_DB]) indexed_resource = indexed_fut.result(3.0) INDEXED = IndexedDBStorageActor(client, indexed_resource.get("actor", "")) ``` -------------------------------- ### GET /DeviceActor/get_description Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.html Retrieves the description of the device currently being managed by the actor. ```APIDOC ## GET /DeviceActor/get_description ### Description Retrieves detailed information and metadata about the device connected via the Gecko Remote Debugging Protocol. ### Method GET ### Endpoint /DeviceActor/get_description ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **description** (object) - A dictionary containing device-specific properties such as name, version, and capabilities. #### Response Example { "name": "Firefox", "version": "120.0", "platform": "linux" } ``` -------------------------------- ### GET /root/tabs Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.html Retrieves a list of all currently open browser tabs. ```APIDOC ## GET /root/list_tabs ### Description Retrieves a list of all currently open browser tabs managed by the RootActor. ### Method GET ### Endpoint /root/list_tabs ### Response #### Success Response (200) - **tabs** (array) - A list of tab objects containing details about each open tab. #### Response Example { "tabs": [ { "id": "tab-1", "title": "Example Domain", "url": "https://example.com" } ] } ``` -------------------------------- ### Initialize and Use RootActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.root.html Demonstrates how to instantiate the RootActor and invoke basic methods to retrieve information about the current browser session. This requires an active connection to the RDP server. ```python from geckordp.actors.root import RootActor # Assuming 'client' is an established RDP connection root = RootActor(client) # List available tabs tabs = root.list_tabs() # Get the current active tab current_tab = root.current_tab() ``` -------------------------------- ### ProcessActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.descriptors.html Interacts with the process actor to get target information and watchers. ```APIDOC ## ProcessActor API ### Description Provides methods to interact with the Firefox process actor. ### Methods - `get_target()`: Retrieves information about the target process. - `get_watcher()`: Retrieves a watcher for process events. ``` -------------------------------- ### Define Main Entry Point with CLI Profile Argument Source: https://github.com/jpramosi/geckordp/blob/master/docs/examples/list_tabs.html This script serves as the main entry point for the application. It checks for a command-line argument to set the profile name, defaulting to 'geckordp' if no argument is provided. ```python if __name__ == "__main__": profile_name: str = "geckordp" from sys import argv if len(argv) > 1: profile_name: str = str(argv[1]) main(profile_name) ``` -------------------------------- ### GET /root/get_process Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.root.html Retrieves a specific process actor by its process ID. ```APIDOC ## GET /root/get_process ### Description Fetches the actor for a specific process based on the provided PID. ### Method GET ### Endpoint /root/get_process ### Parameters #### Query Parameters - **pid** (int) - Required - The process ID to retrieve. ### Response #### Success Response (200) - **process** (object) - The process actor. #### Response Example { "process": "processActor123" } ``` -------------------------------- ### Initialize and Use WorkerActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.descriptors.worker.html Demonstrates how to instantiate the WorkerActor and utilize its primary methods for managing worker lifecycle and target retrieval. ```python from geckordp.actors.descriptors.worker import WorkerActor # Initialize the actor worker_actor = WorkerActor(*args, **kwargs) # Detach the worker actor worker_actor.detach() # Retrieve the associated target target = worker_actor.get_target() ``` -------------------------------- ### GET /root/current_tab Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.root.html Retrieves the currently active tab in the browser session. ```APIDOC ## GET /root/current_tab ### Description Retrieves the actor representing the currently active tab. ### Method GET ### Endpoint /root/current_tab ### Response #### Success Response (200) - **tab** (object) - The actor object for the current tab. #### Response Example { "tab": "tabActor1" } ``` -------------------------------- ### Initialize and Use ProcessActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/process.html Demonstrates how to instantiate the ProcessActor class and access its primary methods for retrieving target and watcher information. ```python from geckordp.actors.process import ProcessActor # Initialize the actor process_actor = ProcessActor(*args, **kwargs) # Retrieve associated target and watcher target = process_actor.get_target() watcher = process_actor.get_watcher() ``` -------------------------------- ### WebSocketActor API Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.web_socket.html Provides methods to start and stop listening to WebSocket events. ```APIDOC ## WebSocketActor ### Description Manages WebSocket connections within the geckordp framework. It allows for starting and stopping the listening process for WebSocket events. ### Class `actors.web_socket.WebSocketActor` ### Methods #### `start_listening()` - **Description**: Initiates listening for WebSocket events. - **Method**: (Implicitly called via actor interaction) #### `stop_listening()` - **Description**: Stops listening for WebSocket events. - **Method**: (Implicitly called via actor interaction) ### Example Usage (Conceptual) ```python from geckordp.actors.web_socket import WebSocketActor # Assuming `client` is an initialized geckordp client instance ws_actor = WebSocketActor(client) # To start listening (typically handled internally by geckordp upon connection) # ws_actor.start_listening() # To stop listening # ws_actor.stop_listening() ``` ### Related Resources - [WebSocket Specification](https://github.com/mozilla/gecko-dev/blob/master/devtools/shared/specs/websocket.js) ``` -------------------------------- ### Initialize and Use HeapSnapshotActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.heap_snapshot.html Demonstrates how to instantiate the HeapSnapshotActor and utilize the transfer_heap_snapshot method to handle heap snapshot data transfers. ```python from geckordp.actors.heap_snapshot import HeapSnapshotActor # Initialize the actor actor = HeapSnapshotActor(*args, **kwargs) # Transfer a heap snapshot by ID response = actor.transfer_heap_snapshot("snapshot_id_123") ``` -------------------------------- ### GET /actors/walker/children Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.walker.html Retrieves the children of a specific node within the DOM tree. ```APIDOC ## GET /actors/walker/children ### Description Fetches the child nodes for a given node actor. ### Method GET ### Endpoint /actors/walker/children ### Parameters #### Query Parameters - **node_actor** (string) - Required - The actor ID of the parent node. ### Request Example { "node_actor": "node123" } ### Response #### Success Response (200) - **children** (array) - List of child node actors. #### Response Example { "children": ["node124", "node125"] } ``` -------------------------------- ### GET /root/list_tabs Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/actors.root.html Lists all open tabs available in the current browser instance. ```APIDOC ## GET /root/list_tabs ### Description Returns a list of all tabs currently open in the browser. ### Method GET ### Endpoint /root/list_tabs ### Response #### Success Response (200) - **tabs** (array) - A list of tab objects. #### Response Example { "tabs": [{"id": 1, "title": "Example"}, {"id": 2, "title": "Mozilla"}] } ``` -------------------------------- ### Initialize and Control ParentAccessibilityActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/actors/parent_accessibility.html Demonstrates how to instantiate the ParentAccessibilityActor and utilize its lifecycle methods to manage accessibility state. ```python from geckordp.actors.accessibility.parent_accessibility import ParentAccessibilityActor # Initialize the actor actor = ParentAccessibilityActor(*args, **kwargs) # Bootstrap the accessibility service actor.bootstrap() # Enable accessibility features actor.enable() # Disable accessibility features actor.disable() ``` -------------------------------- ### Create Firefox Profile with GeckoRDP Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.profile.html Creates and initializes a new Firefox profile with a specified name. Returns an instance of FirefoxProfile if successful, or None if the profile already exists. Raises RuntimeError if profile initialization fails. ```python from geckordp.profile import ProfileManager profile_manager = ProfileManager() new_profile = profile_manager.create("my_new_profile") if new_profile: print("Profile created successfully.") else: print("Profile already exists.") ``` -------------------------------- ### Initialize and Use AccessibleWalkerActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.accessibility.accessible_walker.html Demonstrates how to instantiate the AccessibleWalkerActor and utilize its primary methods for accessibility inspection and interaction. ```python from geckordp.actors.accessibility.accessible_walker import AccessibleWalkerActor # Initialize the actor walker = AccessibleWalkerActor(*args, **kwargs) # Example usage of accessibility methods walker.start_audit(options={"rules": ["color-contrast"]}) walker.highlight_accessible("accessible_id_here") walker.unhighlight() ``` -------------------------------- ### GET /walker/query_selector Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.html Executes a CSS selector query on the DOM to find a specific node. ```APIDOC ## GET /walker/query_selector ### Description Queries the DOM for the first element matching the provided CSS selector string. ### Method GET ### Endpoint /walker/query_selector ### Parameters #### Query Parameters - **selector** (string) - Required - The CSS selector to search for. ### Request Example { "selector": ".my-class" } ### Response #### Success Response (200) - **nodeActor** (string) - The actor ID of the found node. #### Response Example { "nodeActor": "server0.conn0.child1" } ``` -------------------------------- ### Initialize GeckoRDP Actors Source: https://github.com/jpramosi/geckordp/blob/master/docs/examples/actor_initialization.html This script demonstrates the process of cloning a Firefox profile, launching the browser in headless mode, and connecting to the RootActor using the RDPClient. It serves as a template for initializing various actors available in the geckordp library. ```python import argparse from geckordp.actors.root import RootActor from geckordp.firefox import Firefox from geckordp.profile import ProfileManager from geckordp.rdp_client import RDPClient def main(): parser = argparse.ArgumentParser() parser.add_argument("--host", type=str, default="localhost") parser.add_argument("--port", type=int, default="6000") args, _ = parser.parse_known_args() pm = ProfileManager() profile_name = "geckordp" pm.clone("default-release", profile_name) profile = pm.get_profile_by_name(profile_name) profile.set_required_configs() Firefox.start("https://example.com/", args.port, profile_name, ["-headless"]) client = RDPClient() client.connect(args.host, args.port) ROOT = RootActor(client) if __name__ == "__main__": main() ``` -------------------------------- ### AccessibilityActor Source: https://github.com/jpramosi/geckordp/blob/master/docs/geckordp.actors.accessibility.html The AccessibilityActor provides methods to bootstrap accessibility, get simulators, traits, and walkers. ```APIDOC ## AccessibilityActor API ### Description Provides access to accessibility features and configurations within the browser. ### Methods - **bootstrap()**: Initializes the accessibility actor. - **get_simulator()**: Retrieves the accessibility simulator. - **get_traits()**: Fetches accessibility traits. - **get_walker()**: Returns an accessibility walker instance. ``` -------------------------------- ### POST /profile/create Source: https://github.com/jpramosi/geckordp/blob/master/docs/genindex.html Creates a new browser profile using the ProfileManager. ```APIDOC ## POST /profile/create ### Description Initializes and creates a new browser profile for the debugging session. ### Method POST ### Endpoint /profile/create ### Parameters #### Request Body - **name** (string) - Required - The name of the profile to be created. ### Request Example { "name": "test-profile" } ### Response #### Success Response (200) - **status** (string) - Confirmation of profile creation. #### Response Example { "status": "success" } ```