feat(plugin-webview): support domStorageAccess for ArkWeb DOM storage - #77
Merged
richerfu merged 2 commits intoAug 18, 2026
Merged
Conversation
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.
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).
Contributor
Author
|
嗯很好,现在和文档里面描述的一样,是默认关闭了 |
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.
Linked Issues
Closes #76
Summary
Add a
dom_storage_accessoption toWebviewCreateRequest, threaded through thenamed N-API
ohos.webview.CreateRequestinto the ArkTSWebviewPlugin, socallers can control ArkWeb's DOM storage (localStorage/sessionStorage).
Motivation
ArkWeb disables DOM storage by default unless
.domStorageAccess(true)isexplicitly set on the
Web()component. The plugin never sets it, so:window.localStorageisnullCannot read properties of null(white screen)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: adddom_storage_access: Option<bool>fielddom_storage_access(bool)builder method toWebviewCreateRequest; extend thecreate_request_retains_optional_value_semanticstest.plugins/webview/src/main/ets/WebviewPlugin.ets: adddomStorageAccess?toWebviewCreatePayload, pass it throughWebviewSurface.create, and call.domStorageAccess(data.domStorageAccess ?? false)inBuildWebview.demo/.../types/*/Index.d.ts: regenerate theWebviewCreateRequestdeclarationwith the new field.
Default behavior
Defaults to disabled (
?? false), matching ArkWeb's official documentedbehavior that DOM storage is off unless explicitly enabled. This is a breaking
change in behavior from the previous commit (which defaulted to
true), butaligns with the platform's native default and the official ArkWeb API
specification.
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 yourWebviewCreateRequestto preservefunctionality.
If this breaking change is unacceptable, the default can be flipped back to
trueinWebviewPlugin.ets.Verification
cargo check -p openharmony-ability-plugin-webviewpasses.cargo test -p openharmony-ability-plugin-webview --lib(runs in CI with theOHOS toolchain; the host cannot link the OHOS
.libsys crates).