[py] Align BiDi script module with the cross-binding API design#17624
Merged
Conversation
Adds the script-module surface from the BiDi protocol API design doc: - add_error_handler / add_console_handler deliver ScriptError and ConsoleMessage payloads carrying source URL, line/column numbers and a formatted stack trace; the existing add_javascript_error_handler / add_console_message_handler keep their generated log-entry payloads - clear_error_handlers / clear_console_handlers / clear_dom_mutation_handlers counterparts for every handler family - pin() now returns a PinnedScript (a str subclass, so existing code using the return value as a script ID keeps working) and execute(pinned, code) returns a non-raising ScriptResult(value, error, realm) - add_dom_mutation_handler grows an opt-in mutation_types parameter (attributes, childList, characterData); the default stays attributes-only for compatibility The subscription machinery moves out of manifest glue strings into a new py/private/_script_handlers.py helper module (same pattern as _network_handlers.py), with LogHandlerRegistry sharing one log.entryAdded subscription across all console/error handlers and DomMutationRegistry owning the observer preload scripts and script.message channel. The childList/characterData observation uses a Python-side extended listener; the shared javascript/bidi-support/bidi-mutation-listener.js is intentionally untouched (Java and JS bindings consume it) - converging the bindings on the extended listener is follow-up work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issues
💥 What does this PR do?
Aligns
driver.scriptwith the Script Module section of the BiDi Protocol API Design (Phase 5, following #17619 and #17623):add_error_handler(callback)/add_console_handler(callback)deliver the doc'sScriptError/ConsoleMessagepayloads carrying source URL, line/column numbers and a formatted stack trace (extracted from the BiDistackTracecall frames). The longer-standingadd_javascript_error_handler/add_console_message_handlerkeep their generated log-entry payloads unchangedclear_error_handlers()/clear_console_handlers()/clear_dom_mutation_handlers()counterparts for every handler family (each clears both the doc-named and legacy registrations of its category)pin()now returns aPinnedScript(id, source, realm)— astrsubclass, so existing code that treats the return value as a plain script ID keeps working — andexecute(pinned, code)returns a non-raisingScriptResult(value, error, realm); the legacyexecute(function_declaration, *args)path is unchangedadd_dom_mutation_handler(callback, mutation_types=...)can now observechildListandcharacterDatamutations (DomMutationgainstype,target,added_nodes,removed_nodes); the default stays attributes-only so existing handlers see no behavior change🔧 Implementation Notes
py/private/_script_handlers.pyhelper module (same pattern as_network_handlers.py):LogHandlerRegistryshares a singlelog.entryAddedsubscription across all console/error handlers (previously each handler family managed its own bookkeeping), andDomMutationRegistryowns the observer preload scripts and thescript.messagechannelscript.addPreloadScriptarguments may only be channels, so the mutation-type options are inlined into the preload function declaration rather than passed as a LocalValue argumentjavascript/bidi-support/bidi-mutation-listener.jsis intentionally untouched — Java (RemoteScript) and the JS binding embed it, so the extended listener (attributes/childList/characterData behind an options object) lives Python-side in the helper module for now🤖 AI assistance
_script_handlers.py, manifest glue, and tests, from the BiDi Protocol API Design doc💡 Additional Considerations
bidi_script_testspass unmodified on both browsersbidi_script_testsintegration suites green on Chrome and Firefox (90 tests each, including 7 new alignment tests and 4 new mutation-type tests)[WIP]; naming here follows the doc as written (add_error_handler,add_console_handler,clear_*)bidi-mutation-listener.js(Java/JS currently emit attributes only); cross-binding parity for the doc-aligned naming is also follow-upcancel(), extra-headers API🔄 Types of changes