[TIMOB-8018] Android: WebView: beforeload event fires twice if url is invalid
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Do |
Resolution Date | 2020-01-09T21:41:30.000+0000 |
Affected Version/s | Release 2.0.0, Release 1.8.2, Release 3.1.0 |
Fix Version/s | n/a |
Components | Android |
Labels | parity, reprod |
Reporter | Dustin Hyde |
Assignee | Unknown |
Created | 2012-03-14T15:30:06.000+0000 |
Updated | 2020-01-09T21:41:30.000+0000 |
Description
When an invalid url is loaded from a webview, two beforeload events are fired (when one is expected).
A valid url results in one beforeload event, as expected.
iOS has the correct behavior (beforeload is loaded once if an invalid url is loaded).
Steps to Reproduce:
1. Run code, click 'Open Invalid URL'.
var win = Ti.UI.createWindow({
backgroundColor:'blue'
});
var buttonGoogle = Ti.UI.createButton({
title:'Open Google',
top:'20%',
height:'30%',
left:'10%',
right:'10%'
});
buttonGoogle.addEventListener('click', function(){
var webView = Ti.UI.createWebView({
url:'http://www.google.com'
});
webView.addEventListener('load', function(){
alert('load: ' + webView.url);
});
webView.addEventListener('beforeload', function(){
alert('beforeload: ' + webView.url);
});
webView.addEventListener('error', function(){
alert('error: ' + webView.url);
});
win.add(webView);
var button = Ti.UI.createButton({
title:'Close',
right:0,
bottom:0,
height:'10%',
width:'20%'
});
button.addEventListener('click', function(){
win.remove(webView);
});
webView.add(button);
});
win.add(buttonGoogle);
var buttonInvalid = Ti.UI.createButton({
title:'Open Invalid URL',
bottom:'20%',
height:'30%',
left:'10%',
right:'10%'
});
buttonInvalid.addEventListener('click', function(){
var webView = Ti.UI.createWebView({
url:'http://xxx'
});
webView.addEventListener('load', function(){
alert('load: ' + webView.url);
});
webView.addEventListener('beforeload', function(){
alert('beforeload: ' + webView.url);
});
webView.addEventListener('error', function(){
alert('error: ' + webView.url);
});
win.add(webView);
var button = Ti.UI.createButton({
title:'Close',
right:0,
bottom:0,
height:'10%',
width:'20%'
});
button.addEventListener('click', function(){
win.remove(webView);
});
webView.add(button);
});
win.add(buttonInvalid);
win.open();
Expected Result:
One beforeload event should fire, with alerts.
Actual Result:
Two beforeload events fire.
The problem reproduce with release 3.0.2 and master release 3.1.0 tested on Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 Device: Samsung galaxy s duos Android version: 4.0.4 Android Emulator: Android SDK version: 2.2
Why this bug still exists?
[~yiluxiangbei] You may find you get better support on a free, open-source product if you remain professional. One of the bugs you commented on was invalid, the other is still open, but does not have many watchers. What is the exact problem you are experiencing? Do you have sample test code?
Hello,@Ingo Muschenetz. I'm sorry about the word.I use both method setUrl and reload.They triggered twice beforeload and once load.I use beforeload event to show activityIndicator and load event to get data from database.The code like this: Now I'm only use setUrl no reload method.It can work well.I sugguest you to describe it on the docs. webview.addEventListener('beforeload', function(e) { logger.info("beforeload"); activityIndicator.show(); }); webview.addEventListener('load', function(e) { //change content webUtil = require('utils/webUtil'); var beginDate = new Date(); logger.info("---------------getContent start:" + beginDate.getTime()); content = webUtil.getContent(this); logger.info(content); var endDate = new Date(); logger.info("---------------getContent end:" + endDate.getTime() + " use time:" + (endDate.getTime() - beginDate.getTime())); var date = new Date(); Ti.App.fireEvent('app:changeContent', { time: date.getTime(), type: this.menu.type, code: this.menu.code, pageId: this.menu.pageId, newsId: this.menu.newsId, content: content }); logger.info("load"); activityIndicator.hide(); });
Issue is reproducible using the following environment. Tested on: Device : Google Nexus 5, Android Version: 4.4.2 SDK: 3.2.3.v20140328110916 CLI version : 3.2.3-alpha2 OS : MAC OSX 10.9.2 Alloy: 1.3.1 ACS: 1.0.14 npm:1.3.2 Appcelerator Studio, build: 3.2.3.201403271839 titanium-code-processor: 1.1.1-alpha XCode : 5.1
I am able to reproduce this issue with the following environment; Pixel (7.1) Studio 4.9.0.201705302345 Ti SDK 6.1.1.v20170623141152 Appc NPM 4.2.9 Appc CLI 6.2.1 Ti CLI 5.0.13 Alloy 1.9.11 Arrow 2.0.0 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131
It has been decided that this issue should be closed as “Won’t do.” This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. If community members feel that the issue is still valid, please create a new ticket. Please reference this closed ticket number, include SDK used, comments, and code that demonstrates/reproduces the issue.