Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cb51292

Browse files
authored
[web] Ensure Flutter adds a generator meta-tag. (#55714)
Adds a `meta name="generator" content="Flutter"` tag when the engine UI initializes. ## Issues Fixes flutter/flutter#156262 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 9924084 commit cb51292

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/web_ui/lib/src/engine/initialization.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ Future<void> initializeEngineUi() async {
229229
RawKeyboard.initialize(onMacOs: ui_web.browser.operatingSystem == ui_web.OperatingSystem.macOs);
230230
KeyboardBinding.initInstance();
231231

232+
// Ensures Flutter renders a global "generator" meta-tag.
233+
ensureMetaTag('generator', 'Flutter');
234+
232235
if (!configuration.multiViewEnabled) {
233236
final EngineFlutterWindow implicitView =
234237
ensureImplicitViewInitialized(hostElement: configuration.hostElement);

lib/web_ui/lib/src/engine/util.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,19 @@ void setThemeColor(ui.Color? color) {
722722
}
723723
}
724724

725+
/// Ensure a "meta" tag with [name] and [content] is set on the page.
726+
void ensureMetaTag(String name, String content) {
727+
final DomElement? existingTag =
728+
domDocument.querySelector('meta[name=$name][content=$content]');
729+
730+
if (existingTag == null) {
731+
final DomHTMLMetaElement meta = createDomHTMLMetaElement()
732+
..name = name
733+
..content = content;
734+
domDocument.head!.append(meta);
735+
}
736+
}
737+
725738
bool? _ellipseFeatureDetected;
726739

727740
/// Draws CanvasElement ellipse with fallback.

lib/web_ui/test/engine/initialization_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:js/js_util.dart' as js_util;
88
import 'package:test/bootstrap/browser.dart';
99
import 'package:test/test.dart';
1010
import 'package:ui/src/engine.dart' as engine;
11+
import 'package:ui/src/engine/dom.dart';
1112
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
1213

1314
@JS('_flutter')
@@ -76,6 +77,10 @@ void testMain() {
7677
// Check that the object we captured is actually a loader
7778
expect(pluginsRegistered, isTrue, reason: 'Plugins should be immediately registered in autoStart mode.');
7879
expect(appRan, isTrue, reason: 'App should run immediately in autoStart mode');
80+
81+
// After starting the engine, the meta-generator tag should be on the page
82+
final DomElement? meta = domDocument.querySelector('meta[name=generator][content=Flutter]');
83+
expect(meta, isNotNull, reason: 'The generator meta-tag should be added when Flutter initializes its UI.');
7984
});
8085

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

0 commit comments

Comments
 (0)