webdriverio / webdriverio/devtools
Hybrid sessions lose webview DOM capture: native detection is fixed at session start
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10
- Forks
- 2
- Avg merge
- 1d 29m
- Merged PRs (30d)
- 23
Description
isNativeAppSession answers from startup capabilities and is never revisited, so a session's answer is fixed for its whole lifetime. A hybrid app switched into a webview context does have a document, and every page-side guard keyed on that predicate keeps skipping.
Raised by review on #375 (thread). Filed rather than fixed there: the fix is outside that PR's scope and cannot be verified without a hybrid app on a real device.
Not new, but newly load-bearing
The residual is declared in the predicate's own docstring, and has been since the service's version landed in #371:
Residual: a hybrid app switched into a webview context does have a document, and no capability can say so — only
getContext()knows that.
What #375 changes is how much rides on it. Before it, selenium-devtools, nightwatch-devtools and selenium-devtools-py gated nothing — every page-side call was attempted unconditionally, so a hybrid session's webview portion was captured by accident. After it, those adapters gate collector injection, the DOM drain, the performance read and the per-action snapshot on a predicate that answers "native" for the whole session. The webview portion of the trace therefore carries no DOM evidence.
None of the three claims native support today, so this is an unimplemented case rather than a promise broken — but it is a real behaviour change for anyone driving a hybrid app through them.
Why the obvious fix is wrong
Ungating is not the answer. Treating a document-less session as web is the expensive direction: the service's post-action settle reads a page tag, treats the failure as a navigation, then polls a probe that can only fail for its full 8 s timeout, per action. That is #351 (40-60 s per run in per-action probes), and it is what #350/#372 exist to remove. Protecting hybrid by ungating would restore that cost for every pure-native user.
The shape of a fix
Document availability has to follow the current runtime context, not the startup bag:
- Appium exposes
getContext()/getContexts(); the active context isNATIVE_APPor aWEBVIEW_*string. - It cannot be read per guard — that is a round trip on the hot path, which reintroduces the cost above in a different form. It has to be cached and invalidated when the context changes.
- The invalidation point is the context-switch command itself, which every adapter already sees in its command hook.
There is no runtime-context awareness anywhere in the repo today. Grepping getContext|currentContext|NATIVE_APP|WEBVIEW|setContext|switchContext across packages/*/src returns only:
core/element-snapshot.ts— anandroid.webkit.WebViewentry in the class-name → role map, and'webview'in a role list.core/locators/xml-parsing.ts— a comment about WebView content in page source.nightwatch-devtools/src/constants.ts—currentContextas an entry inINTERNAL_COMMANDS_TO_IGNORE, i.e. Nightwatch's own command filtered out of the action list, not detection.
Scope
- A context-aware document-availability answer, cached and invalidated on context switch, sitting beside
isNativeAppSessionrather than replacing it — the capability answer is still the right one at bringup, before any context exists. -
service,selenium-devtools,nightwatch-devtools,selenium-devtools-pyconsume it at the sites #372 gated. - Verified on a real hybrid app: a trace whose webview portion carries DOM, mutations and element snapshots, and whose native portion still costs no failed round trips.
- Decide what a webview→native switch does to an already-injected collector.
Verification needs a hybrid app on a real device or a device cloud; CI cannot cover it, so the PR should state what was run and on what.
Related
- #372 — the cross-adapter gating this follows from.
- #371, #350 — the WDIO-side work, where the residual was first documented.
- #351 — the per-action probe cost that makes ungating the wrong fix.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating isNativeAppSession and the gating sites introduced by #372 across service, selenium-devtools, nightwatch-devtools, and selenium-devtools-py; then inspect each adapter's context-switch command hook. Done means cached context-aware availability preserves native fast paths, captures DOM, mutations, and snapshots in webviews, handles webview-to-native transitions, and is verified on a real hybrid app or device cloud.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools, mobile-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100