|
3 | 3 | import { CSSType, ContainerView, EventData, File, Property, Trace, booleanConverter, knownFolders, path } from '@nativescript/core';
|
4 | 4 | import { isEnabledProperty } from '@nativescript/core/ui/core/view';
|
5 | 5 | import { metadataViewPort, promisePolyfill, webViewBridge } from './nativescript-webview-bridge-loader';
|
6 |
| -import * as URL from 'url'; |
| 6 | +import normalizeUrl from 'normalize-url'; |
7 | 7 |
|
8 | 8 | export interface ViewPortProperties {
|
9 | 9 | width?: number | 'device-width';
|
@@ -58,6 +58,7 @@ export const webConsoleProperty = new Property<WebViewExtBase, boolean>({
|
58 | 58 | valueConverter: booleanConverter
|
59 | 59 | });
|
60 | 60 |
|
| 61 | + |
61 | 62 | export const displayZoomControlsProperty = new Property<WebViewExtBase, boolean>({
|
62 | 63 | name: 'displayZoomControls',
|
63 | 64 | defaultValue: true,
|
@@ -101,6 +102,15 @@ export const isScrollEnabledProperty = new Property<WebViewExtBase, boolean>({
|
101 | 102 | valueConverter: booleanConverter
|
102 | 103 | });
|
103 | 104 |
|
| 105 | +export const normalizeUrlsProperty = new Property<WebViewExtBase, boolean>({ |
| 106 | + name: 'normalizeUrls', |
| 107 | + defaultValue: true, |
| 108 | + valueConverter: booleanConverter |
| 109 | +}); |
| 110 | +export const normalizeUrlsOptionsProperty = new Property<WebViewExtBase, any>({ |
| 111 | + name: 'normalizeUrlsOptions' |
| 112 | +}); |
| 113 | + |
104 | 114 | export type ViewPortValue = boolean | ViewPortProperties;
|
105 | 115 | export const viewPortProperty = new Property<WebViewExtBase, ViewPortValue>({
|
106 | 116 | name: 'viewPortSize',
|
@@ -363,7 +373,9 @@ export class UnsupportedSDKError extends Error {
|
363 | 373 |
|
364 | 374 | @CSSType('WebView')
|
365 | 375 | export abstract class WebViewExtBase extends ContainerView {
|
366 |
| - public webConsole: boolean; |
| 376 | + public webConsoleEnabled: boolean; |
| 377 | + public normalizeUrls: boolean; |
| 378 | + public normalizeUrlsOptions: any; |
367 | 379 |
|
368 | 380 | public static readonly supportXLocalScheme: boolean;
|
369 | 381 |
|
@@ -1092,15 +1104,11 @@ export abstract class WebViewExtBase extends ContainerView {
|
1092 | 1104 | }
|
1093 | 1105 |
|
1094 | 1106 | public normalizeURL(url: string): string {
|
1095 |
| - if (!url) { |
1096 |
| - return url; |
1097 |
| - } |
1098 |
| - |
1099 |
| - if (url.startsWith(this.interceptScheme)) { |
| 1107 | + if (!url || !this.normalizeUrls || url.startsWith(this.interceptScheme)) { |
1100 | 1108 | return url;
|
1101 | 1109 | }
|
1102 | 1110 |
|
1103 |
| - return URL.parse(url).format(); |
| 1111 | + return normalizeUrl(url, this.normalizeUrlsOptions); |
1104 | 1112 | }
|
1105 | 1113 |
|
1106 | 1114 | /**
|
@@ -1561,6 +1569,8 @@ cacheModeProperty.register(WebViewExtBase);
|
1561 | 1569 | databaseStorageProperty.register(WebViewExtBase);
|
1562 | 1570 | debugModeProperty.register(WebViewExtBase);
|
1563 | 1571 | webConsoleProperty.register(WebViewExtBase);
|
| 1572 | +normalizeUrlsProperty.register(WebViewExtBase); |
| 1573 | +normalizeUrlsOptionsProperty.register(WebViewExtBase); |
1564 | 1574 | displayZoomControlsProperty.register(WebViewExtBase);
|
1565 | 1575 | domStorageProperty.register(WebViewExtBase);
|
1566 | 1576 | srcProperty.register(WebViewExtBase);
|
|
0 commit comments