Repository navigation
Conversation
New Context and New Persistent Context passed a relative recordHar path to the Node process as given, so the HAR file ended up in Browser's own wrapper folder. A relative path is now relative to the output directory, as a .zip path of tracing is.
A library that hands over its own context with adoptContext had to reach into Browser's internals to trace and record it the way New Context does. - adopted_context_options returns tracing, recordVideo and recordHar by the rules of New Context, including ROBOT_FRAMEWORK_BROWSER_TRACING and Browser's trace and video folders. - register_adopted_context registers the adopted context afterwards, so that the keyword calls become trace groups and the log embeds the video.
The import argument describes what adoptContext does in one sentence. Its options and the Python methods for libraries are described on the website.
adopted_context_options returns a typed dictionary with tracing, recordVideo and recordHar, None when off, so that a library can pass it on to the extension function as keyword arguments. Its parameters take Browser's RecordVideo and RecordHar, as New Context does.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Adopted HAR options can forward string booleans to Playwright without conversion.
1 open finding
What changed in this PR
Adds public helpers for libraries adopting Browser contexts while aligning tracing, video, and HAR behavior with New Context.
Changes:
- Adds adopted-context option generation and registration.
- Resolves relative HAR paths against the output directory.
- Adds unit and acceptance coverage.
| File | Description |
|---|---|
Browser/browser.py |
Adds adopted-context APIs and shortens extension help. |
Browser/keywords/playwright_state.py |
Resolves relative HAR paths. |
Browser/utils/data_types.py |
Defines adopted-context option types. |
Browser/utils/__init__.py |
Exports the new type. |
utest/test_adopted_context.py |
Tests options and registration. |
atest/test/01_Browser_Management/record_har.robot |
Verifies relative HAR paths. |
🧠 Review effort: Balanced
This branch has not been deployed
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.

Follow-up to #5318, as discussed there.
With #5318, Browser starts tracing an adopted context, but a library still has to work out the trace path, the video folder and size and the HAR path itself, and register the context for the keyword groups in the trace and for the video in the log. The Electron library did that through internals of
PlaywrightState, such as_resolve_trace_file,_set_video_pathand_embed_video. This PR gives libraries built on Browser two public methods for it, so that an adopted context follows Browser's settings in the same style asNew Context.Browser.adopted_context_options(tracing=None, recordVideo=None, recordHar=None)returns anAdoptedContextOptions, a typed dictionary withtracing,recordVideoandrecordHar,Nonewhen off. They follow the rules ofNew Context:tracing=TrueandROBOT_FRAMEWORK_BROWSER_TRACINGgive Browser's trace folder, a video gets Browser's video folder and 1280x720 by default, and relative paths are resolved as forNew Context. The keys are named like the options, so a library can pass them on to its extension function as keyword arguments.Browser.register_adopted_context(context_id, options, video_path=None)registers the adopted context afterwards: the keyword calls become groups in the trace, and the log embeds the video. It returns the video path, or an empty string without a video.A library in Python then does:
Two related changes:
recordHarpaths:New ContextandNew Persistent Contextpassed thepathofrecordHarto the Node process as given, so a relative path put the HAR file into thewrapperfolder of the installed package. A relative path is now relative to the output directory, as a.zippath oftracingis, andadopted_context_optionsuses the same rule. UnlikerecordVideoandtracing,recordHarhas no default location yet. Browser could give it one, for examplebrowser/har/<unique name>.harwhen thepathis left out, and adopted contexts would get it throughadopted_context_optionstoo. I left that out to keep this PR small, but I can add it here or in a separate PR if you like the idea.jsextensionhelp: with Let libraries built on Browser hand over their own BrowserContext #5318, the description of thejsextensionimport argument had grown into a full reference ofadoptContextand its options. That is too much detail for an import argument, so it now describesadoptContextin one sentence and links to the website. The details are on the JavaScript extensions page instead, including the two methods above, updated in Document adoptContext for JavaScript extensions robotframework-browser.org#21.Tests:
utest/test_adopted_context.py: the options followNew Context, including the global tracing setting, the video defaults and HAR paths. Registering adds the trace groups and embeds the video, and a video path withoutrecordVideois ignored.atest/test/01_Browser_Management/record_har.robot: a relative HAR path ends up in the output directory.There are no Node or protocol changes. I verified it locally with
inv lint, the Python unit tests, and the acceptance test suitesRecord HarandAdopt Context(inv atest-robot --suite …), with Chromium only. The Electron library uses the two methods instead of Browser's internals, and its tests pass against this branch.AI / tooling disclosure
This contribution was prepared with assistance from Claude Code (Anthropic). I reviewed the result manually, understand the changes, verified them locally, and confirm that I have the right to submit this contribution under the project license.