Add high-level BiDi script pin and unpin commands - #17801
Add high-level BiDi script pin and unpin commands#17801mayank-at-sauce wants to merge 3 commits into
Conversation
PR Summary by QodoAdd Ruby BiDi Script#pin/#unpin wrappers for preload scripts
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
19 rules 1.
|
|
Code review by qodo was updated up to the latest commit b895acc |
|
Code review by qodo was updated up to the latest commit 2e6f2ba |
|
We need to clarify the behavior we expect from this, since it is inconsistent between bindings right now. |
|
Also, we're migrating things to implement off of the newly generated |
|
Hi @titusfortner sure, let me connect with you on slack. Thanks! |
Part of #13992 — implements the pin / unpin cells for the Ruby binding.
What does this PR do?
Adds driver.script.pin and driver.script.unpin to the Ruby bindings, bringing the high-level BiDi Script API closer to parity with Python/Java/JS (which already have these).
pin takes a function declaration and registers it as a BiDi preload script, so it runs on every new browsing context before the page's own scripts — handy for injecting helpers, polyfills, or instrumentation. It returns an id that you pass to unpin to remove it later:
id = driver.script.pin('() => { window.helper = () => 42; }')
driver.navigate.to("https://example.com")
window.helper is available on the page
driver.script.unpin(id)
Implementation Notes
Under the hood these are thin wrappers over the existing script.addPreloadScript / script.removePreloadScript BiDi commands, sent via @bidi.send_cmd — the same pattern the network handlers already use. I kept the surface deliberately minimal (return the raw preload-script id rather than a wrapper object) to match how the JS binding exposes it. Script#initialize now keeps a reference to the bidi object so both the log handlers and these commands can share it; behaviour when BiDi isn't enabled is unchanged (it still raises on driver.script). Added RBS signatures and integration specs covering both the pin path (script runs on a freshly navigated document) and the unpin path (script no longer runs).