Skip to content

Commit 6cd640f

Browse files
authored
Merge pull request #13 from sebj54/master
iOS - Add debug mode + emit events without data
2 parents 96fc522 + 300f3bb commit 6cd640f

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The custom `NSURLProtocol` used with UIWebView is shared with all instances of t
8787
| builtInZoomControls | true / false | Android: Is the built-in zoom mechanisms being used |
8888
| cacheMode | default / no_cache / cache_first / cache_only | Android: Set caching mode. |
8989
| databaseStorage | true / false | Android: Enable/Disabled database storage API. Note: It affects all webviews in the process. |
90-
| debugMode | true / false | Android: Enable chrome debugger for webview on Android. Note: Applies to all webviews in App |
90+
| debugMode | true / false | Enable chrome debugger for webview on Android and Safari debugger for webview on iOS. Note: Applies to all webviews in App |
9191
| displayZoomControls | true / false | Android: displays on-screen zoom controls when using the built-in zoom mechanisms |
9292
| domStorage | true / false | Android: Enable/Disabled DOM Storage API. E.g localStorage |
9393
| scalesPageToFit | UIWebView: Should webpage scale to fit the view? Defaults to false |

src/webview/index.common.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ export const isScrollEnabledProperty = new Property<WebViewExtBase, boolean>({
103103
valueConverter: booleanConverter
104104
});
105105

106-
export const normalizeUrlsProperty = new Property<WebViewExtBase, boolean>({
107-
name: 'normalizeUrls',
108-
defaultValue: true,
109-
valueConverter: booleanConverter
110-
});
111-
112106
export const limitsNavigationsToAppBoundDomainsProperty = new Property<WebViewExtBase, boolean>({
113107
name: 'limitsNavigationsToAppBoundDomains',
114108
valueConverter: booleanConverter
@@ -389,7 +383,6 @@ export class UnsupportedSDKError extends Error {
389383
@CSSType('WebView')
390384
export abstract class WebViewExtBase extends ContainerView {
391385
public webConsoleEnabled: boolean;
392-
public normalizeUrls: boolean;
393386

394387
public static readonly supportXLocalScheme: boolean;
395388

@@ -551,7 +544,6 @@ export abstract class WebViewExtBase extends ContainerView {
551544
* Callback for the loadFinished-event. Called from the native-webview
552545
*/
553546
public async _onLoadFinished(url: string, error?: string): Promise<LoadFinishedEventData> {
554-
url = this.normalizeURL(url);
555547
if (Trace.isEnabled()) {
556548
Trace.write(`WebViewExt._onLoadFinished("${url}", ${error || void 0} ${this.autoInjectJSBridge}) - > Injecting webview-bridge JS code`, WebViewTraceCategory, Trace.messageType.info);
557549
}
@@ -857,8 +849,6 @@ export abstract class WebViewExtBase extends ContainerView {
857849
}
858850

859851
if (lcSrc.startsWith(this.interceptScheme) || lcSrc.startsWith('http://') || lcSrc.startsWith('https://') || lcSrc.startsWith('file:///')) {
860-
src = this.normalizeURL(src);
861-
862852
if (originSrc !== src) {
863853
// Make sure the src-property reflects the actual value.
864854
try {
@@ -1115,17 +1105,6 @@ export abstract class WebViewExtBase extends ContainerView {
11151105
this.autoInjectJavaScriptBlocks = this.autoInjectJavaScriptBlocks.filter((data) => data.name !== name);
11161106
}
11171107

1118-
public normalizeURL(url: string): string {
1119-
if (!url || !this.normalizeUrls || url.startsWith(this.interceptScheme)) {
1120-
return url;
1121-
}
1122-
try {
1123-
return require('url').parse(url).format();
1124-
} catch (error) {
1125-
return url;
1126-
}
1127-
}
1128-
11291108
/**
11301109
* Ensure fetch-api is available.
11311110
*/
@@ -1588,7 +1567,6 @@ cacheModeProperty.register(WebViewExtBase);
15881567
databaseStorageProperty.register(WebViewExtBase);
15891568
debugModeProperty.register(WebViewExtBase);
15901569
webConsoleProperty.register(WebViewExtBase);
1591-
normalizeUrlsProperty.register(WebViewExtBase);
15921570
displayZoomControlsProperty.register(WebViewExtBase);
15931571
domStorageProperty.register(WebViewExtBase);
15941572
srcProperty.register(WebViewExtBase);

src/webview/index.ios.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
WebViewTraceCategory,
88
allowsInlineMediaPlaybackProperty,
99
autoInjectJSBridgeProperty,
10+
debugModeProperty,
1011
limitsNavigationsToAppBoundDomainsProperty,
1112
mediaPlaybackRequiresUserActionProperty,
1213
scrollBarIndicatorVisibleProperty,
@@ -406,6 +407,16 @@ export class AWebView extends WebViewExtBase {
406407
this.loadWKUserScripts(enabled);
407408
}
408409

410+
[debugModeProperty.getDefault]() {
411+
return false;
412+
}
413+
414+
[debugModeProperty.setNative](enabled) {
415+
const nativeView = this.nativeViewProtected;
416+
417+
nativeView.inspectable = !!enabled;
418+
}
419+
409420
[scrollBounceProperty.getDefault]() {
410421
const nativeView = this.nativeViewProtected;
411422

@@ -747,7 +758,13 @@ export class WKScriptMessageHandlerNotaImpl extends NSObject implements WKScript
747758

748759
try {
749760
const message = JSON.parse(webViewMessage.body as string);
750-
owner.onWebViewEvent(message.eventName, JSON.parse(message.data));
761+
762+
try {
763+
owner.onWebViewEvent(message.eventName, JSON.parse(message.data));
764+
} catch (err) {
765+
owner.writeTrace(`userContentControllerDidReceiveScriptMessage(${userContentController}, ${webViewMessage}) - couldn't parse data: ${message.data}`, Trace.messageType.error);
766+
owner.onWebViewEvent(message.eventName, message.data);
767+
}
751768
} catch (err) {
752769
owner.writeTrace(`userContentControllerDidReceiveScriptMessage(${userContentController}, ${webViewMessage}) - bad message: ${webViewMessage.body}`, Trace.messageType.error);
753770
}

0 commit comments

Comments
 (0)