Script¶
ScriptModule ¶
Module for executing JavaScript in the browser.
Source code in bidiwave/modules/script.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
get_realms
async
¶
get_realms(context: BrowsingContext | str | None = None, type: str | None = None) -> list[RealmInfo]
Gets information about available realms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
BrowsingContext | str | None
|
Filter by context ID. None = all realms. |
None
|
type
|
str | None
|
Filter by realm type ("window", "dedicated-worker", "shared-worker", "service-worker"). None = all. |
None
|
Returns:
| Type | Description |
|---|---|
list[RealmInfo]
|
List of RealmInfo. |
Source code in bidiwave/modules/script.py
add_preload_script
async
¶
add_preload_script(function_declaration: str, arguments: list[dict[str, Any]] | None = None, contexts: list[str] | None = None, user_contexts: list[str] | None = None, sandbox: str | None = None) -> ScriptAddPreloadScriptResult
Adds a preload script with optional channel support.
Unlike preload.addPreloadScript, this variant supports channels for bidirectional communication between the preload script and the client via script.message events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function_declaration
|
str
|
JavaScript function to execute. |
required |
arguments
|
list[dict[str, Any]] | None
|
Arguments to pass to the function. |
None
|
contexts
|
list[str] | None
|
Context IDs to apply to. None = all. |
None
|
user_contexts
|
list[str] | None
|
User context IDs to apply to. |
None
|
sandbox
|
str | None
|
Sandbox name to run the script in. |
None
|
Returns:
| Type | Description |
|---|---|
ScriptAddPreloadScriptResult
|
ScriptAddPreloadScriptResult with script ID and channel. |
Source code in bidiwave/modules/script.py
remove_preload_script
async
¶
Removes a preload script by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_id
|
str
|
ID of the preload script to remove. |
required |
Source code in bidiwave/modules/script.py
Add preload script with channels¶
Unlike preload.addPreloadScript, script.addPreloadScript supports
channels for bidirectional communication between the preload script and
the client via script.message events.
result = await client.script.add_preload_script(
function_declaration="(channel) => { channel('hello from page'); }",
arguments=[{"type": "channel", "value": {"channel": "my-channel"}}],
contexts=["context-id-1"],
)
print(result.script) # preload script ID
print(result.channel) # channel name for communication
Receive messages from the preload script: