Skip to content

Commit

Permalink
fix: devtools display error when debugger with the real machine
Browse files Browse the repository at this point in the history
  • Loading branch information
yifei8 authored and andycall committed Jan 11, 2024
1 parent e60cf02 commit 02eab15
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion webf/lib/src/devtools/modules/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import 'dart:convert';
import 'dart:math' as math;
import 'dart:typed_data';

import 'package:meta/meta.dart';
Expand Down Expand Up @@ -188,6 +189,8 @@ class InspectPageModule extends UIInspectorModule {
switch (method) {
case 'startScreencast':
sendToFrontend(id, null);
_devToolsMaxWidth = params?['maxWidth'] ?? 0;
_devToolsMaxHeight = params?['maxHeight'] ?? 0;
startScreenCast();
break;
case 'stopScreencast':
Expand Down Expand Up @@ -222,10 +225,20 @@ class InspectPageModule extends UIInspectorModule {

int? _lastSentSessionID;
bool _isFramingScreenCast = false;
int _devToolsMaxWidth = 0;
int _devToolsMaxHeight = 0;

void _frameScreenCast(Duration timeStamp) {
Element root = document.documentElement!;
root.toBlob().then((Uint8List screenShot) {
// the devtools of some pc do not automatically scale. so modify devicePixelRatio for it
double? devicePixelRatio;
double viewportWidth = document.viewport!.viewportSize.width;
double viewportHeight = document.viewport!.viewportSize.height;
if (_devToolsMaxWidth > 0 && _devToolsMaxHeight > 0 && viewportWidth > 0 && viewportHeight > 0) {
devicePixelRatio = math.min(_devToolsMaxHeight / viewportHeight, _devToolsMaxHeight / viewportHeight);
devicePixelRatio = math.min(devicePixelRatio, document.controller.ownerFlutterView.devicePixelRatio);
}
root.toBlob(devicePixelRatio: devicePixelRatio).then((Uint8List screenShot) {
String encodedImage = base64Encode(screenShot);
_lastSentSessionID = timeStamp.inMilliseconds;
InspectorEvent event = PageScreenCastFrameEvent(ScreenCastFrame(
Expand Down

0 comments on commit 02eab15

Please sign in to comment.