Files
pipelines/app/lib/features/artifacts/ui/artifact_html_view_web.dart
T

29 lines
819 B
Dart

import 'dart:js_interop';
import 'package:flutter/widgets.dart';
import 'package:web/web.dart' as web;
/// A sandboxed iframe: the empty `sandbox` attribute applies every
/// restriction, so the document cannot run script or leave the frame.
class InertHtmlView extends StatelessWidget {
const InertHtmlView({super.key, required this.html});
final String html;
@override
Widget build(BuildContext context) => HtmlElementView.fromTagName(
key: ValueKey<int>(html.hashCode),
tagName: 'iframe',
onElementCreated: (element) {
final frame = element as web.HTMLIFrameElement;
frame.setAttribute('sandbox', '');
frame.srcdoc = html.toJS;
frame.style
..border = 'none'
..width = '100%'
..height = '100%'
..backgroundColor = 'white';
},
);
}