Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,15 @@ class FirebaseCoreWeb extends FirebasePlatform {
/// You must ensure the Firebase script is injected before using the service.
List<String> get _ignoredServiceScripts {
try {
JSObject? ignored =
final ignored =
globalContext.getProperty('flutterfire_ignore_scripts'.toJS);

// Cannot be done with Dart 3.2 constraints
// ignore: invalid_runtime_check_with_js_interop_types
if (ignored is Iterable) {
// ignore: invalid_runtime_check_with_js_interop_types
return (ignored! as Iterable)
.map((e) => e.toString())
.toList(growable: false);
if (ignored != null && ignored.isA<JSArray>()) {
return (ignored as JSArray<JSAny?>).toDart.map((entry) {
if (entry != null && entry.isA<JSString>()) {
return (entry as JSString).toDart;
}
return entry?.toString() ?? 'null';
}).toList(growable: false);
}
} catch (e) {
// Noop
Expand All @@ -135,6 +134,10 @@ class FirebaseCoreWeb extends FirebasePlatform {
return [];
}

/// Services listed on `window.flutterfire_ignore_scripts`.
@visibleForTesting
List<String> get ignoredServiceScripts => _ignoredServiceScripts;

final String _defaultTrustedPolicyName = 'flutterfire-';

/// Injects a `script` with a `src` dynamically into the head of the current
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2026 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

@TestOn('browser')
library;

import 'dart:js_interop';
import 'dart:js_interop_unsafe';

import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
tearDown(() {
globalContext.delete('flutterfire_ignore_scripts'.toJS);
});

test('reads service names from a JS array on window', () {
// Matches `window.flutterfire_ignore_scripts = ['analytics'];` in index.html.
globalContext.callMethod(
'eval'.toJS,
"window.flutterfire_ignore_scripts = ['analytics', 'firestore']".toJS,
);

expect(
FirebaseCoreWeb().ignoredServiceScripts,
['analytics', 'firestore'],
);
});

test('returns an empty list when the window property is missing', () {
expect(FirebaseCoreWeb().ignoredServiceScripts, isEmpty);
});

test('returns an empty list when the window property is not an array', () {
globalContext['flutterfire_ignore_scripts'] = 'analytics'.toJS;

expect(FirebaseCoreWeb().ignoredServiceScripts, isEmpty);
});
}
Loading