Skip to content

feat(plugin-webview): support domStorageAccess for ArkWeb DOM storage - #77

Merged
richerfu merged 2 commits into
harmony-contrib:mainfrom
Islatri:feat/webview-dom-storage-access
Aug 18, 2026
Merged

feat(plugin-webview): support domStorageAccess for ArkWeb DOM storage#77
richerfu merged 2 commits into
harmony-contrib:mainfrom
Islatri:feat/webview-dom-storage-access

Conversation

@Islatri

@Islatri Islatri commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Linked Issues

Closes #76

Summary

Add a dom_storage_access option to WebviewCreateRequest, threaded through the
named N-API ohos.webview.CreateRequest into the ArkTS WebviewPlugin, so
callers can control ArkWeb's DOM storage (localStorage/sessionStorage).

Motivation

ArkWeb disables DOM storage by default unless .domStorageAccess(true) is
explicitly set on the Web() component. The plugin never sets it, so:

  • window.localStorage is null
  • frontends throw Cannot read properties of null (white screen)
  • token / settings / history cannot be persisted

Android and iOS WebViews enable DOM storage by default, so this is a platform
gap every webview consumer hits on OpenHarmony.

Changes

  • crates/plugin-webview/src/lib.rs: add dom_storage_access: Option<bool> field
    • dom_storage_access(bool) builder method to WebviewCreateRequest; extend the
      create_request_retains_optional_value_semantics test.
  • plugins/webview/src/main/ets/WebviewPlugin.ets: add domStorageAccess? to
    WebviewCreatePayload, pass it through WebviewSurface.create, and call
    .domStorageAccess(data.domStorageAccess ?? false) in BuildWebview.
  • demo/.../types/*/Index.d.ts: regenerate the WebviewCreateRequest declaration
    with the new field.

Default behavior

Defaults to disabled (?? false), matching ArkWeb's official documented
behavior that DOM storage is off unless explicitly enabled. This is a breaking
change
in behavior from the previous commit (which defaulted to true), but
aligns with the platform's native default and the official ArkWeb API
specification.

Per ArkWeb documentation:

When domStorageAccess is not explicitly called, DOM Storage API is disabled by default.
Passing undefined or null results in false.

Callers that need DOM storage must explicitly opt in with
.dom_storage_access(true).

Breaking Change Note

This is a behavioral breaking change for existing consumers that rely on the
previous commit's default-enabled behavior. If you are upgrading from the
intermediate commit where default was true, please explicitly set
.dom_storage_access(true) in your WebviewCreateRequest to preserve
functionality.

If this breaking change is unacceptable, the default can be flipped back to
true in WebviewPlugin.ets.

Verification

  • cargo check -p openharmony-ability-plugin-webview passes.
  • cargo test -p openharmony-ability-plugin-webview --lib (runs in CI with the
    OHOS toolchain; the host cannot link the OHOS .lib sys crates).

ArkWeb disables DOM storage (localStorage/sessionStorage) by default, so window.localStorage is null and frontends throw 'Cannot read properties of null' (white screen) and cannot persist tokens/settings.

Add a dom_storage_access option to WebviewCreateRequest and thread it through the named N-API CreateRequest into the ArkTS WebviewPlugin, defaulting to enabled to match Android/iOS WebView behavior.
@Islatri

Islatri commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

哦其实我更倾向于和ArkWeb的行为保持一致,默认关闭,但提供一个接口可以开启的话就行,但是早上时间仓促AI默认给他开了,这个得晚上下班之后回来再调了

ArkWeb only enables DOM storage when domStorageAccess is explicitly set to
true; leaving it unset keeps localStorage/sessionStorage disabled. The previous
commit defaulted to enabled, diverging from ArkWeb's documented default and
silently changing behavior for existing callers.

Respect the platform default: when unset, stay disabled; callers opt in
via WebviewCreateRequest::dom_storage_access(true).
@Islatri

Islatri commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

嗯很好,现在和文档里面描述的一样,是默认关闭了

@richerfu
richerfu merged commit 746a00a into harmony-contrib:main Aug 18, 2026
1 check passed
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.

[Webview] DOM storage (localStorage/sessionStorage) disabled on ArkWeb

2 participants