{ "id": "63210", "key": "TIMOB-2578", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "3", "description": "The problem is a duplicate of an existing issue.", "name": "Duplicate" }, "resolutiondate": "2012-03-05T10:50:35.000+0000", "created": "2011-04-15T03:23:15.000+0000", "priority": { "name": "Trivial", "id": "5" }, "labels": [], "versions": [ { "id": "11225", "name": "Release 1.5.0", "archived": true, "released": true, "releaseDate": "2010-12-14" } ], "issuelinks": [ { "id": "15528", "type": { "id": "10002", "name": "Duplicate", "inward": "is duplicated by", "outward": "duplicates" }, "outwardIssue": { "id": "87150", "key": "TIMOB-7849", "fields": { "summary": "iOS: TiUIWebView beforeload event doesn't have the URL ", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "Medium", "id": "3" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "ngupta", "key": "ngupta", "displayName": "Neeraj Gupta", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-03-22T20:36:11.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}

When a user click on a link inside the WebView, the received\r\nevent URL property isn't correctly setted.

\r\n

Code:
\r\nwebview.addEventListener('beforeload', function(e) {

\r\n
\r\nTitanium.API.info(e);\r\n
\r\n

});

\r\n

Output:
\r\nsource = \"[object TiUIWebView]\";
\r\ntype = beforeload;
\r\nurl =\r\n\"file://localhost/Users/myuser/Workspace/TitaniumWorkspace/MyApp/Resources/procedureHTML/06_07_2010/11_00.html\";
\r\n}

\r\n

Context:
\r\nI have a local HTML file with different type of links (towards PDF,\r\nDOC, etc). I have to prevent some default behavior.

\r\n

Note:
\r\nWhen also registering a \"load\" event, which is called just after,\r\nthe url is correctly configured.

\r\n

SDK 1.5.0 GA & 1.5.1 nightly

{html}", "attachment": [], "flagged": false, "summary": "iOS: WebView event beforeLoad.url property", "creator": { "name": "jérémyr", "key": "jérémyr", "displayName": "Jérémy R", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "jérémyr", "key": "jérémyr", "displayName": "Jérémy R", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "128825", "author": { "name": "hal", "key": "hal", "displayName": "hal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Jeremy

\n

While this may be a valid bug, you have not have explained this\nticket thoroughly-enough to be useful. Would you follow \nthis guide and fill in the missing information, please?

\n

Thanks

{html}", "updateAuthor": { "name": "hal", "key": "hal", "displayName": "hal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:15.000+0000", "updated": "2011-04-15T03:23:15.000+0000" }, { "id": "128826", "author": { "name": "chrisd", "key": "chrisd", "displayName": "Chris D", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Please assign and increase priority of this ticket for iOS.

\n

Anyone developing web browsing apps is going to eventually need\nthe ability to examine the URL before loading in the web view for\nURL filtering and information pop-ups, etc.

\n

Here's a Use Case:

\n

In iOS create a WebView with TouchScreen enabled and it loads\nthe URL defined at WebView creation. User touches the screen on a\nhyperlink and WebView starts to load a malicious or advertising\nsite. The app creator can provide in the app a whitelist of trusted\nURLS (or domains) to prevent loading of such websites and alert the\nuser that the site has been blocked. To do this the url property of\nthe WebView must be updated at the 'beforeload' event or there is\nno way to detect the pending page load.

\n

Per your workflow I've posted to the community Q&A for\npotential work arounds.

\n

Thanks, Chris

{html}", "updateAuthor": { "name": "chrisd", "key": "chrisd", "displayName": "Chris D", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:15.000+0000", "updated": "2011-04-15T03:23:15.000+0000" }, { "id": "128827", "author": { "name": "davecourt", "key": "davecourt", "displayName": "Dave Court", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

In addition, there seems to be no way to prevent the webview\nfrom loading an URL, after inspecting it during the beforeload\nevent.

\n

On iOS, you'd normally use shouldStartLoadWithRequest in the\nwebview proxy to do this. But I see from the code that Appcelerator\nunconditionally returns YES on that method.

\n

To implement the sort of behaviour described in this ticket, I\nthink it's necessary to provide some sort of bridge to that method\n- or to provide an additional API method to abort the current URL,\nusable within the beforeload event. Without that, some important\nfunctionality is crippled compared with native iOS apps.

\n

Note that I've tried issuing stopLoading() from within\nbeforeload, but it doesn't work - presumably because the event is\nasynchronous and so can't get to the request in time.

\n

I presume there's an equivalent way of doing this on Android,\nbut I haven't looked into it yet.

{html}", "updateAuthor": { "name": "davecourt", "key": "davecourt", "displayName": "Dave Court", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:16.000+0000", "updated": "2011-04-15T03:23:16.000+0000" }, { "id": "128828", "author": { "name": "corey", "key": "corey", "displayName": "corey", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

This would be a huge help. Being able to detect what URL the\nuser is trying to load before it loads is a must for security and\nfor app integration with webview.

\n

I for one would like to capture a URL from a share button in\nwebview and preform facebook, twitter etc functions with in the app\nrather than going to the web version of said social site.

\n

Please fix the beforeload event to update the URL, also, being\nable to stop the URL from loading, like cancelLoad() or something\nwould be great too.

\n

THanks, keep up the good work!

{html}", "updateAuthor": { "name": "corey", "key": "corey", "displayName": "corey", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:16.000+0000", "updated": "2011-04-15T03:23:16.000+0000" }, { "id": "128829", "author": { "name": "corey", "key": "corey", "displayName": "corey", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Please Fix This!

{html}", "updateAuthor": { "name": "corey", "key": "corey", "displayName": "corey", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:16.000+0000", "updated": "2011-04-15T03:23:16.000+0000" }, { "id": "128830", "author": { "name": "netpro2k", "key": "netpro2k", "displayName": "netpro2k", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I agree, getting before-load to work, or better yet a wrapper\naround shouldStartLoadWithRequest would be extremely helpful. Our\ncurrent workaround is to use load and then reload the previous url\nimmediately after performing the required actions, but this is less\nthan ideal for many reasons.

{html}", "updateAuthor": { "name": "netpro2k", "key": "netpro2k", "displayName": "netpro2k", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:17.000+0000", "updated": "2011-04-15T03:23:17.000+0000" }, { "id": "128831", "author": { "name": "jimc.", "key": "jimc.", "displayName": "Jim C.", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Is there a fix/feature planned? Apologize if I missed a roadmap\ndocument somewhere.

\n

I am developing an eCommerce application. I would like to do the\nfollowing on iOS and Android. Currently testing on iOS.

\n\n
\n\nwebview1.addEventListener('beforeload',function(e){\n    logger('webview1 beforeload event : webview1.url = ', webview1.url);\n        \n    // Broken.  \n    logger('webview1 beforeload event : e.url = ', e.url );     \n        \n    logger('webview1 stopLoading call', '');\n    webview1.stopLoading();\n        \n    Titanium.UI.createAlertDialog({title:'Alert', message:'Browsing Canceled.'}).show();\n        \n    logger('webview1 goBack call', '');     \n    webview1.goBack();\n});\n
\n

-Jim

{html}", "updateAuthor": { "name": "jimc.", "key": "jimc.", "displayName": "Jim C.", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:17.000+0000", "updated": "2011-04-15T03:23:17.000+0000" }, { "id": "128832", "author": { "name": "diego", "key": "diego", "displayName": "Diego", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I am building a safe browser app for the iPhone and it requires\nvalidating the url before it is loaded. Seems 'beforeload' event\nand being able to call webView.stopLading() if the url is not\nallowed is fundamental in this case.

\n

Any idea on when this problems will be fixed?

\n

Keep up the great work!
\nDiego

{html}", "updateAuthor": { "name": "diego", "key": "diego", "displayName": "Diego", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:17.000+0000", "updated": "2011-04-15T03:23:17.000+0000" }, { "id": "128833", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Still not enough information in the ticket to be able to handle\nit.

{html}", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:17.000+0000", "updated": "2011-04-15T03:23:17.000+0000" }, { "id": "128834", "author": { "name": "davecourt", "key": "davecourt", "displayName": "Dave Court", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I found this article, which contains a neat trick that will\nmaybe help in cases where you're in control of the HTML and able to\nconvert elements appropriately:

\n

\nhttp://boydlee.com/appcelerator-titanium/capturing-titanium-events-...

\n

It's certainly what I'll be trying to work around this\nproblem.

{html}", "updateAuthor": { "name": "davecourt", "key": "davecourt", "displayName": "Dave Court", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:23:18.000+0000", "updated": "2011-04-15T03:23:18.000+0000" }, { "id": "133479", "author": { "name": "trueicecold", "key": "trueicecold", "displayName": "Yaniv Nagar", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Let me elaborate on the problem:\n\nwhenever using the \"beforeLoad\" event, the e.url returns the original url the webView was opened from, and not the url that the webView is going to load next.\n\nI've tried to look at TiUIWebView.m, and changed:\n\nNSDictionary *event = url == nil ? nil : [NSDictionary dictionaryWithObject:[url absoluteString] forKey:@\"url\"];\n\nto:\n\nNSURL *currentURL = webView.request.URL;\nNSDictionary *event = url == nil ? nil : [NSDictionary dictionaryWithObject:[currentURL absoluteString] forKey:@\"url\"];\n\nwhich gave better results, the link is now updated, but I always get the last link I was in, and not the next one.\n\nIf I'm at page A and clicking to move to page B, I'll get A as the \"currentURL\".", "updateAuthor": { "name": "trueicecold", "key": "trueicecold", "displayName": "Yaniv Nagar", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-05-12T00:19:04.000+0000", "updated": "2011-05-12T00:19:04.000+0000" }, { "id": "133483", "author": { "name": "trueicecold", "key": "trueicecold", "displayName": "Yaniv Nagar", "active": true, "timeZone": "America/Los_Angeles" }, "body": "At last! I created a fix for it :)\n\nI should have used the \"shouldStartLoadWithRequest\" method instead of the \"didStartLoad\" one!\n\ngo to /Library/Application Support/Titanium/mobilesdk/osx/1.6.2 (or 1.7)/iphone/Classes and edit TiUIWebView.m\n\nin the \"shouldStartLoadWithRequest\" method, look for:\n\nif ([scheme hasPrefix:@\"http\"] || [scheme hasPrefix:@\"app\"] || [scheme hasPrefix:@\"file\"] || [scheme hasPrefix:@\"ftp\"])\n{\nreturn YES;\n}\n\nand replace with:\n\n\tif ([scheme hasPrefix:@\"http\"] || [scheme hasPrefix:@\"app\"] || [scheme hasPrefix:@\"file\"] || [scheme hasPrefix:@\"ftp\"])\n\t{\n NSString *urlExtension = newUrl.absoluteString;\n NSArray *urlChunks = [urlExtension componentsSeparatedByString: @\".\"];\n urlExtension = [urlChunks lastObject];\n if ([urlExtension isEqualToString:@\"zip\"] || [urlExtension isEqualToString:@\"pdf\"] || [urlExtension isEqualToString:@\"doc\"])\n {\n if ([self.proxy _hasListeners:@\"fileDownload\"])\n {\n NSDictionary *event = newUrl == nil ? nil : [NSDictionary dictionaryWithObject:[newUrl absoluteString] forKey:@\"url\"];\n [self.proxy fireEvent:@\"fileDownload\" withObject:event];\n } \n return NO;\n } \n\t\treturn YES;\n\t}\n\nsave it and clean the project in the titanium IDE (Project/Clean), and build again.\nNow, for every url with the extension of ipa or zip (you can add more, look at the code), you'll get the \"fileDownload\" event in Titanium :)\n\nI hope appcelerator will add this fix in the next sdk version :)", "updateAuthor": { "name": "trueicecold", "key": "trueicecold", "displayName": "Yaniv Nagar", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-05-12T06:53:14.000+0000", "updated": "2011-05-12T07:09:10.000+0000" }, { "id": "167308", "author": { "name": "connysvensson", "key": "connysvensson", "displayName": "connysvensson", "active": true, "timeZone": "Europe/Berlin" }, "body": "Ok, so everyone has agreed this is a bug and we have a solution for it. People are screaming for a fix (check Q&A). Why isn't this fixed yet? It's stopping us from building the apps we want. I have patched the code myself as described above but that shouldn't be necessary.", "updateAuthor": { "name": "connysvensson", "key": "connysvensson", "displayName": "connysvensson", "active": true, "timeZone": "Europe/Berlin" }, "created": "2011-09-29T06:31:54.000+0000", "updated": "2011-09-29T06:31:54.000+0000" }, { "id": "168136", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "We cannot accept code submitted in JIRA tickets. If the original author Yaniv Nagar wants to submit a pull request for it and sign the CLA then we can look at the code.", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-10-06T10:42:12.000+0000", "updated": "2011-10-06T10:42:12.000+0000" }, { "id": "185169", "author": { "name": "connysvensson", "key": "connysvensson", "displayName": "connysvensson", "active": true, "timeZone": "Europe/Berlin" }, "body": "What is the duplicate JIRA ticket, so I can follow that?", "updateAuthor": { "name": "connysvensson", "key": "connysvensson", "displayName": "connysvensson", "active": true, "timeZone": "Europe/Berlin" }, "created": "2012-03-06T10:15:41.000+0000", "updated": "2012-03-06T10:15:41.000+0000" }, { "id": "185176", "author": { "name": "ngupta", "key": "ngupta", "displayName": "Neeraj Gupta", "active": true, "timeZone": "America/Los_Angeles" }, "body": "TIMOB-7849", "updateAuthor": { "name": "ngupta", "key": "ngupta", "displayName": "Neeraj Gupta", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-03-06T10:30:14.000+0000", "updated": "2012-03-06T10:30:14.000+0000" }, { "id": "414892", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket as duplicate of the ticket that is mentioned above.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-22T20:36:11.000+0000", "updated": "2017-03-22T20:36:11.000+0000" } ], "maxResults": 18, "total": 18, "startAt": 0 } } }