Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
3 changes: 3 additions & 0 deletions lib/web_ui/lib/src/engine/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ Future<void> initializeEngineUi() async {
RawKeyboard.initialize(onMacOs: ui_web.browser.operatingSystem == ui_web.OperatingSystem.macOs);
KeyboardBinding.initInstance();

// Ensures Flutter renders a global "generator" meta-tag.
ensureMetaTag('generator', 'Flutter');

if (!configuration.multiViewEnabled) {
final EngineFlutterWindow implicitView =
ensureImplicitViewInitialized(hostElement: configuration.hostElement);
Expand Down
13 changes: 13 additions & 0 deletions lib/web_ui/lib/src/engine/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,19 @@ void setThemeColor(ui.Color? color) {
}
}

/// Ensure a "meta" tag with [name] and [content] is set on the page.
void ensureMetaTag(String name, String content) {
final DomElement? existingTag =
domDocument.querySelector('meta[name=$name][content=$content]');

if (existingTag == null) {
final DomHTMLMetaElement meta = createDomHTMLMetaElement()
..name = name
..content = content;
domDocument.head!.append(meta);
}
}

bool? _ellipseFeatureDetected;

/// Draws CanvasElement ellipse with fallback.
Expand Down
5 changes: 5 additions & 0 deletions lib/web_ui/test/engine/initialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:js/js_util.dart' as js_util;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart' as engine;
import 'package:ui/src/engine/dom.dart';
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

@JS('_flutter')
Expand Down Expand Up @@ -76,6 +77,10 @@ void testMain() {
// Check that the object we captured is actually a loader
expect(pluginsRegistered, isTrue, reason: 'Plugins should be immediately registered in autoStart mode.');
expect(appRan, isTrue, reason: 'App should run immediately in autoStart mode');

// After starting the engine, the meta-generator tag should be on the page
final DomElement? meta = domDocument.querySelector('meta[name=generator][content=Flutter]');
expect(meta, isNotNull, reason: 'The generator meta-tag should be added when Flutter initializes its UI.');
});

// We cannot test anymore, because by now the engine has registered some stuff that can't be rewound back.
Expand Down