You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中替代Android WebView domStorageEnabled设置与Firebase报错解决

Fixing Firebase Persistence Error in flutter_webview_plugin

Hey there, I’ve been in your shoes before—you fixed this exact Firebase error in native Android WebView by flipping domStorageEnabled = true, but now you’re trying to replicate that fix in Flutter with flutter_webview_plugin and can’t find the right setting. Let’s get this sorted:

The Equivalent Settings in flutter_webview_plugin

The plugin exposes direct matches to the native WebView settings you relied on. You need to enable three key flags when setting up your WebviewScaffold:

  • withJavascript: true: Firebase’s JS SDK can’t run without JavaScript enabled, so this is non-negotiable.
  • withLocalStorage: true: Turns on localStorage support, which Firebase uses as part of its persistence layer.
  • domStorageEnabled: true: This is the direct equivalent to Android’s domStorageEnabled—it unlocks DOM storage, the missing piece for Firebase’s persistence to work.

Here’s a complete code example to implement these fixes:

import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:flutter/material.dart';

class FirebaseWebView extends StatelessWidget {
  final String targetUrl = "your-website-url-goes-here";

  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
      url: targetUrl,
      withJavascript: true,
      withLocalStorage: true,
      domStorageEnabled: true, // This is the core fix you're looking for!
      appBar: AppBar(
        title: const Text("Your WebView"),
      ),
    );
  }
}

Quick Check: Plugin Version

If you don’t see the domStorageEnabled parameter in your code editor, you’re likely using an older version of flutter_webview_plugin. Head to your pubspec.yaml and update to the latest version (double-check for the most recent number):

dependencies:
  flutter:
    sdk: flutter
  flutter_webview_plugin: ^0.4.0 # Replace with the latest available version

If It Still Doesn’t Work…

Try these troubleshooting steps:

  • Clear your app’s cache and storage from your device’s settings, then restart the app—old cached data can sometimes break persistence logic.
  • Double-check that your website’s Firebase JS SDK configuration is identical to when it worked with native Android WebView.
  • Verify your website’s Content Security Policy (CSP) isn’t blocking localStorage or DOM storage—look for directives like script-src or storage-src that might restrict access.

That should get Firebase’s persistence working just like it did in your native Android WebView.

内容的提问来源于stack exchange,提问作者Hemanth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:22:35