Skip to content

Add opt-in complete console export snapshots#149

Open
zzanzifeng wants to merge 1 commit into
HuolalaTech:mainfrom
zzanzifeng:feat/complete-console-export
Open

Add opt-in complete console export snapshots#149
zzanzifeng wants to merge 1 commit into
HuolalaTech:mainfrom
zzanzifeng:feat/complete-console-export

Conversation

@zzanzifeng

@zzanzifeng zzanzifeng commented Jun 3, 2026

Copy link
Copy Markdown

Summary

  • add consoleExportMode?: 'original' | 'complete' with original as the default
  • use the shared ConsoleExportMode enum/helper internally instead of repeating mode string literals
  • serialize console/error arguments as getter-safe JSON snapshots when complete is enabled and the value can be fully snapshotted
  • fall back to the original lazy atom preview when a console argument contains unsupported/opaque values such as DOM nodes, Promise, WeakMap/WeakSet, Blob/File/FormData/Headers, or host objects
  • preserve existing lazy atom preview behavior in original mode
  • wire complete snapshots across Browser, Mini Program base, React Native, Harmony, and MP eval paths
  • keep arrays readable in complete snapshots, including arrays whose elements are objects
  • add targeted coverage for circular values, getters, arrays, fallback-to-atom behavior, Map/Set values, typed arrays, and Browser console behavior

Serialization scope

complete mode is intended to make exported logs useful for common serializable/reference values. It does not try to be a full Chrome DevTools remote-object mirror or a structuredClone replacement.

Covered common cases include:

  • plain objects and nested objects
  • arrays, including arrays of objects
  • Map / Set
  • Date / RegExp
  • ArrayBuffer, typed arrays, and DataView
  • URL / URLSearchParams where available
  • Error, functions, symbols, bigint, undefined
  • circular references as [Circular]
  • accessors as [Getter] / [Setter] without invoking getters

Fallback behavior:

  • each top-level console argument is evaluated independently
  • if any nested value in that argument cannot be fully snapshotted, that argument is sent as the original atom preview instead of JSON
  • this keeps values such as document.body readable as HTMLBodyElement instead of {"__type":"HTMLBodyElement"}

Known limitations:

  • WeakMap / WeakSet contents are not enumerable
  • Promise values are not synchronously expanded
  • DOM nodes, Blob, File, FormData, Headers, class private fields/internal slots, Proxies, and platform-specific host objects are not guaranteed to export complete internals
  • platform runtimes differ, so the snapshot is best-effort for host-specific objects

Companion Web PR

This SDK PR is intended to work with the Web UI export PR:

The Web PR makes the debugger export click-time snapshots as JSON/Markdown. This SDK PR supplies log-time snapshots for common console values so Markdown/JSON exports do not stay limited to lazy atom previews when complete is enabled. Unsupported complete-mode values intentionally remain atom previews so the Web export can mark them as preview-only instead of emitting misleading JSON markers.

Validation

  • yarn workspace @huolala-tech/page-spy-base build
  • yarn workspace @huolala-tech/page-spy-browser build
  • yarn workspace @huolala-tech/page-spy-mp-base build
  • yarn workspace @huolala-tech/page-spy-react-native build
  • yarn jest packages/page-spy-base/tests/atom.test.ts packages/page-spy-browser/tests/plugins/console.test.ts --runInBand
  • targeted ESLint for modified SDK files
  • git diff --check
  • real headless Chrome check confirmed consoleExportMode: 'complete' emits an atom preview for document.body and still emits a JSON snapshot for an array of objects
  • local Docker rebuild of the companion Web app + Chrome CDP smoke test verified the served browser SDK accepts consoleExportMode: 'complete', caches complete object/array snapshots, and falls back DOM values to HTMLBodyElement atom previews

Notes

original remains the default to avoid changing payload size and legacy lazy expansion behavior. Apps that need complete export should opt in with:

new PageSpy({
  consoleExportMode: 'complete'
});

@zzanzifeng
zzanzifeng force-pushed the feat/complete-console-export branch from d3a55f6 to 181b05a Compare June 3, 2026 02:15
Add an original-by-default consoleExportMode option so apps can export common console values as getter-safe log-time snapshots without changing existing lazy atom behavior. Complete mode now falls back to original atom previews when a console argument contains values that cannot be fully snapshotted, such as DOM nodes or opaque host objects.

Constraint: object expansion is lazy across PageSpy platforms, and complete export must not invoke getters or require debugger-side hydration.
Rejected: making complete snapshots the default | it changes payload size and legacy console behavior for existing users.
Rejected: representing unsupported host objects as `{ "__type": "..." }` JSON | it hides the useful original atom preview for DOM and other opaque runtime values.
Confidence: high
Scope-risk: moderate
Directive: keep original mode as the default, use ConsoleExportMode instead of repeated string literals, and preserve getter-safe serialization semantics across browser, MP, React Native, and Harmony paths.
Related: HuolalaTech/page-spy-web#407
Tested: yarn workspace @huolala-tech/page-spy-base build; yarn workspace @huolala-tech/page-spy-browser build; yarn workspace @huolala-tech/page-spy-mp-base build; yarn workspace @huolala-tech/page-spy-react-native build; yarn jest packages/page-spy-base/tests/atom.test.ts packages/page-spy-browser/tests/plugins/console.test.ts --runInBand; targeted eslint for modified SDK files; git diff --check; real headless Chrome check for DOM fallback and array object JSON snapshot
Not-tested: full SDK lint/typecheck because existing unrelated Harmony/path issues are outside this change
@zzanzifeng
zzanzifeng force-pushed the feat/complete-console-export branch from 181b05a to adca81e Compare June 3, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant