fluttercommunity / fluttercommunity/flutter_webview_plugin

Js code contains timer, exit webvie_scaffold, and the timer still runs.

Abierto
#278 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
1.5k
Forks
938
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I use the webview_scaffold to open a web.
the webpage contains contains a timer.
this is a html file I have used:
```

Timer

var s;

function $(id){

return document.getElementById(id);

}

function display(){

var date = new Date();

var str = date.getTime();

$("content").value = str;

console.log("this this a console log..." + str);

s = setTimeout('display()',1000);

}

window.onload = function(){

$("start").onclick =function(){display();}

$("stop").onclick = function(){clearTimeout(s);}

}

```
It means that change the display num and print some log per second.

this is my webviewPage.dart
```
//! WebViewPage
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class AppWebView extends StatelessWidget {
final String url;
final String title;

AppWebView(this.url, this.title);

_renderTitle() {
if (url == null || url.length == 0) {
return new Text(title);
}
return new Row(children: [
//new Expanded(child: new Container()),
new Text(title)
]);
}

@override
Widget build(BuildContext context) {
return new WebviewScaffold(
withJavascript: true,
hidden: false,
url: url,
scrollBar:false,
withLocalUrl: true,
appBar: new AppBar(
title: _renderTitle(),
),
);
}
}
```
when I open the webview to the html file,then I press the start button on this web.Finally I exit the webview.

this is my log:
```
I/flutter ( 4095): 运维页面
I/zygote64( 4095): Compiler allocated 8MB to compile void android.view.ViewRootImpl.performTraversals()
D/ViewRootImpl@d8ee1fe[MainActivity]( 4095): ViewPostIme pointer 0
D/ViewRootImpl@d8ee1fe[MainActivity]( 4095): ViewPostIme pointer 1
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273611702", source: http://192.168.10.104/test.html (24)
V/InputMethodManager( 4095): Starting input: tba=android.view.inputmethod.EditorInfo@560ef34 nm : com.example.dfelectricapp ic=null
I/InputMethodManager( 4095): startInputInner - mService.startInputOrWindowGainedFocus
D/InputMethodManager( 4095): HSIFW - flag : 0 Pid : 4095
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273612709", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273613719", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273614726", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273615730", source: http://192.168.10.104/test.html (24)
D/ViewRootImpl@d8ee1fe[MainActivity]( 4095): ViewPostIme pointer 0
D/ViewRootImpl@d8ee1fe[MainActivity]( 4095): ViewPostIme pointer 1
I/flutter ( 4095): 运维页面show web
I/flutter ( 4095): this is webview dispose
D/InputMethodManager( 4095): HSIFW - flag : 0 Pid : 4095
V/InputMethodManager( 4095): Starting input: tba=android.view.inputmethod.EditorInfo@95fe15d nm : com.example.dfelectricapp ic=null
I/InputMethodManager( 4095): startInputInner - mService.startInputOrWindowGainedFocus
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273617383", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273619384", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273621385", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273623384", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273625384", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273627383", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273629384", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273631384", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273633385", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273635384", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273637385", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273639385", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273641385", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273643385", source: http://192.168.10.104/test.html (24)
I/chromium( 4095): [INFO:CONSOLE(24)] "this this a console log...1545273645385", source: http://192.168.10.104/test.html (24)

```
You can see that I've quit the webview but the log is still being printed.

I try to solve this problem.So here's what I did.
In the webview_scaffold.dart
```
@override
void dispose() {
super.dispose();
webviewReference.reloadUrl(""); //! I add this line
_resizeTimer?.cancel();
webviewReference.close();
if (widget.hidden) {
_onStateChanged.cancel();
}
print("this is webview dispose");
webviewReference.dispose();
}
```
It worked,But I don't know the reason.
Am I right?
I want to know why the js consle log still being printed.
Thanks very much.

btw:
this is flutter doctor print:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.11.7, on Microsoft Windows [Version 10.0.17134.471], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[√] Android Studio (version 3.2)
[√] Connected device (1 available)

• No issues found!

this is the dependencies:
flutter_webview_plugin: ^0.3.0+2

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Reproduce el problema con el temporizador HTML y webviewPage.dart proporcionados; después, inspecciona el ciclo de vida de WebviewScaffold en webview_scaffold.dart, especialmente dispose y la gestión de webviewReference. Determina por qué JavaScript sigue registrando mensajes después de cerrar el scaffold. Se considera completado cuando el temporizador se detiene al salir de la webview sin depender del workaround reloadUrl añadido, y el comportamiento del ciclo de vida está documentado o cubierto por una prueba adecuada, si existe alguna.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
android, dart, flutter, javascript
Área
mobile, web-dev
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.