Closed reesz closed 1 month ago
I don't know what's happening. I can take screenshot of a canvas without any problems with this example:
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isAndroid) {
await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
}
runApp(MaterialApp(
home: MyApp()
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
),);
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("InAppWebView example")),
body: SafeArea(
child: Column(children: <Widget>[
Expanded(
child: InAppWebView(
initialOptions: options,
initialData: InAppWebViewInitialData(
data: """
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<body>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("Hello World",10,50);
</script>
</body>
</html>
"""
),
onLoadStop: (controller, url) async {
await Future.delayed(Duration(seconds: 1));
var screenshot = await controller.takeScreenshot();
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Image.memory(screenshot!),
);
},
);
},
),
),
])),
);
}
}
Or change your URL with https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_canvas_tut_text
So, I think there are some problems with the website itself.
This issue has been automatically closed because it was marked as "answered", and there wasn't any recent activity on this issue.
I had the same problem when use url
@panzikeji could you provide an example URL of the type of content you're using?
flutter_inappwebview: ^4.0.0+4 takeScreenshot doesn't work on all of my real devices canvas example URL: https://app-pre.panzitech.com/preview?file=https://app-prod.obs.cn-east-2.myhuaweicloud.com:443/_4238_1610089676014_161008967145128820694-9834-4475-9257-c5feed21c299.ocf
Solve this problem?
I try to take a screenshot this link https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_canvas_tut_text I got it, No 'Hello World' in Canvas.
In flutter_inappwebview: ^5.4.4+3
If I disable hardwareAcceleration, my maps page doesn't finish loading.
This issue is stale and has been automatically closed because it has been open for more than 365 days with no activity. Please reopen a new issue if you still have it.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.
Environment
Device information: iPhone 11 Pro / iPhone X / iOS 14.4
Description
I'm trying to take a screenshot of the currently displayed webpage with the
takeScreenshot()
method. For regular websites this is working fine – but when trying to capture a webpage that displays all it's content on a canvas-element, the screenshot is only black (background color of the page).I've found this old issue: https://github.com/pichillilorenzo/flutter_inappwebview/issues/409 that talks about having to disable
hardwareAcceleration
for Android, but for me it's affecting iOS.The only weird thing that's throwing me off: When running the app on a simulator, taking the screenshot of canvas-pages works. On all of my real devices (iPhone 6/X/11 Pro) it doesn't.
Expected behavior: Expected the full page, including canvas elements, to show in the screenshot.
Current behavior: Canvas elements are not shown in the screenshot.
Steps to reproduce
Here's a minimal sample project to reproduce the issue. A fullscreen webview that takes a screenshot by tapping on it & displays it afterwards in the bottom left corner. On a real device this always displays a black screenshot. (Ignore the base64 encoding, this is just a left over from the project I copied it over from)
If there's anything else I can provide, please let me know.
Thanks for your time!