Skip to content

Commit 1799915

Browse files
committed
chore(ios): only trace if enabled
1 parent 9f3ba36 commit 1799915

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/webview/index.ios.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,9 @@ export class WKNavigationDelegateNotaImpl extends NSObject implements WKNavigati
620620
const httpMethod = request.HTTPMethod;
621621
const url = request.URL && request.URL.absoluteString;
622622

623-
owner.writeTrace(`webViewDecidePolicyForNavigationActionDecisionHandler: "${url}"`);
623+
if (Trace.isEnabled()) {
624+
Trace.write(`webViewDecidePolicyForNavigationActionDecisionHandler: "${url}"`, WebViewTraceCategory, Trace.messageType.info);
625+
}
624626
if (!url) {
625627
return;
626628
}
@@ -656,16 +658,18 @@ export class WKNavigationDelegateNotaImpl extends NSObject implements WKNavigati
656658

657659
const shouldOverrideUrlLoading = owner._onShouldOverrideUrlLoading(url, httpMethod, navType);
658660
if (shouldOverrideUrlLoading === true) {
659-
owner.writeTrace(
660-
`WKNavigationDelegateClass.webViewDecidePolicyForNavigationActionDecisionHandler("${url}", "${navigationAction.navigationType}") -> method:${httpMethod} "${navType}" -> cancel`
661-
);
662-
decisionHandler(WKNavigationActionPolicy.Cancel);
663-
661+
if (Trace.isEnabled()) {
662+
Trace.write(
663+
`WKNavigationDelegateClass.webViewDecidePolicyForNavigationActionDecisionHandler("${url}", "${navigationAction.navigationType}") -> method:${httpMethod} "${navType}" -> cancel`, WebViewTraceCategory, Trace.messageType.info);
664+
decisionHandler(WKNavigationActionPolicy.Cancel);
665+
}
664666
return;
665667
}
666668
decisionHandler(WKNavigationActionPolicy.Allow);
667669

668-
owner.writeTrace(`WKNavigationDelegateClass.webViewDecidePolicyForNavigationActionDecisionHandler("${url}", "${navigationAction.navigationType}") -> method:${httpMethod} "${navType}"`);
670+
if (Trace.isEnabled()) {
671+
Trace.write(`WKNavigationDelegateClass.webViewDecidePolicyForNavigationActionDecisionHandler("${url}", "${navigationAction.navigationType}") -> method:${httpMethod} "${navType}"`, WebViewTraceCategory, Trace.messageType.info);
672+
}
669673
owner._onLoadStarted(url, navType);
670674
}
671675

@@ -675,7 +679,9 @@ export class WKNavigationDelegateNotaImpl extends NSObject implements WKNavigati
675679
return;
676680
}
677681

678-
owner.writeTrace(`WKNavigationDelegateClass.webViewDidStartProvisionalNavigation("${webView.URL}")`);
682+
if (Trace.isEnabled()) {
683+
Trace.write(`WKNavigationDelegateClass.webViewDidStartProvisionalNavigation("${webView.URL}")`, WebViewTraceCategory, Trace.messageType.info);
684+
}
679685
}
680686

681687
public webViewDidFinishNavigation(webView: WKWebView, navigation: WKNavigation): void {
@@ -684,7 +690,9 @@ export class WKNavigationDelegateNotaImpl extends NSObject implements WKNavigati
684690
return;
685691
}
686692

687-
owner.writeTrace(`WKNavigationDelegateClass.webViewDidFinishNavigation("${webView.URL}")`);
693+
if (Trace.isEnabled()) {
694+
Trace.write(`WKNavigationDelegateClass.webViewDidFinishNavigation("${webView.URL}")`, WebViewTraceCategory, Trace.messageType.info);
695+
}
688696
let src = owner.src;
689697
if (webView.URL) {
690698
src = webView.URL.absoluteString;
@@ -702,7 +710,9 @@ export class WKNavigationDelegateNotaImpl extends NSObject implements WKNavigati
702710
if (webView.URL) {
703711
src = webView.URL.absoluteString;
704712
}
705-
owner.writeTrace(`WKNavigationDelegateClass.webViewDidFailNavigationWithError("${error.localizedDescription}")`);
713+
if (Trace.isEnabled()) {
714+
Trace.write(`WKNavigationDelegateClass.webViewDidFailNavigationWithError("${error.localizedDescription}")`, WebViewTraceCategory, Trace.messageType.info);
715+
}
706716
owner._onLoadFinished(src, error.localizedDescription).catch(() => void 0);
707717
}
708718

@@ -717,7 +727,9 @@ export class WKNavigationDelegateNotaImpl extends NSObject implements WKNavigati
717727
src = webView.URL.absoluteString;
718728
}
719729

720-
owner.writeTrace(`WKNavigationDelegateClass.webViewDidFailProvisionalNavigationWithError(${error.localizedDescription}`);
730+
if (Trace.isEnabled()) {
731+
Trace.write(`WKNavigationDelegateClass.webViewDidFailProvisionalNavigationWithError(${error.localizedDescription}`, WebViewTraceCategory, Trace.messageType.info);
732+
}
721733
owner._onLoadFinished(src, error.localizedDescription).catch(() => void 0);
722734
}
723735
}
@@ -745,7 +757,9 @@ export class WKScriptMessageHandlerNotaImpl extends NSObject implements WKScript
745757
const message = JSON.parse(webViewMessage.body as string);
746758
owner.onWebViewEvent(message.eventName, JSON.parse(message.data));
747759
} catch (err) {
748-
owner.writeTrace(`userContentControllerDidReceiveScriptMessage(${userContentController}, ${webViewMessage}) - bad message: ${webViewMessage.body}`, Trace.messageType.error);
760+
if (Trace.isEnabled()) {
761+
Trace.write(`userContentControllerDidReceiveScriptMessage(${userContentController}, ${webViewMessage}) - bad message: ${webViewMessage.body}`, WebViewTraceCategory, Trace.messageType.error);
762+
}
749763
}
750764
}
751765
}

0 commit comments

Comments
 (0)