diff --git a/TIWebView/Sources/ErrorHandler/WebViewError/WebViewJSError.swift b/TIWebView/Sources/ErrorHandler/WebViewError/WebViewJSError.swift index b81cf0ae..4fb04cda 100644 --- a/TIWebView/Sources/ErrorHandler/WebViewError/WebViewJSError.swift +++ b/TIWebView/Sources/ErrorHandler/WebViewError/WebViewJSError.swift @@ -23,14 +23,25 @@ import Foundation public struct WebViewJSError: WebViewError, Codable { + + public enum CodingKeys: String, CodingKey { + case contentURL + case name + case message + case lineNumber = "line" + case stackTrace = "stack" + } + public let contentURL: URL? public let name: String? - public let message: Int? + public let message: String? + public let lineNumber: Int? public let stackTrace: String? public init(stringURL: String?, name: String?, - message: Int?, + message: String?, + lineNumber: Int?, stackTrace: String?) { if let stringURL = stringURL { @@ -41,6 +52,7 @@ public struct WebViewJSError: WebViewError, Codable { self.name = name self.message = message + self.lineNumber = lineNumber self.stackTrace = stackTrace } } diff --git a/TIWebView/Sources/ErrorHandler/WebViewErrorConstants.swift b/TIWebView/Sources/ErrorHandler/WebViewErrorConstants.swift index 07d266e0..dc9c4745 100644 --- a/TIWebView/Sources/ErrorHandler/WebViewErrorConstants.swift +++ b/TIWebView/Sources/ErrorHandler/WebViewErrorConstants.swift @@ -29,6 +29,10 @@ public enum WebViewErrorConstants { "message" } + static var errorLineNumber: String { + "line" + } + static var errorName: String { "name" } diff --git a/TIWebView/Sources/URLInjector/WebViewUrlInjector.swift b/TIWebView/Sources/URLInjector/WebViewUrlInjector.swift index 89409e49..aa63fc6c 100644 --- a/TIWebView/Sources/URLInjector/WebViewUrlInjector.swift +++ b/TIWebView/Sources/URLInjector/WebViewUrlInjector.swift @@ -50,16 +50,14 @@ public extension WebViewUrlInjector { // MARK: - Helper methods private func evaluteInjection(onWebView webView: WKWebView, injection: WebViewUrlInjection) { - let jsScript = makeJsScript(fromInjection: injection) - - guard !jsScript.isEmpty else { + guard let jsScript = makeJsScript(fromInjection: injection) else { return } webView.evaluateJavaScript(jsScript, completionHandler: nil) } - private func makeJsScript(fromInjection injection: WebViewUrlInjection) -> String { + private func makeJsScript(fromInjection injection: WebViewUrlInjection) -> String? { switch injection { case let .css(css): return cssJsScript(css: css) @@ -69,7 +67,11 @@ public extension WebViewUrlInjector { .components(separatedBy: .newlines) .joined() - return cssJsScript(css: css ?? "") + if let css = css, !css.isEmpty { + return cssJsScript(css: css) + } + + return nil case let .javaScript(script): return script diff --git a/TIWebView/Sources/Views/ViewModels/DefaultWebViewModel.swift b/TIWebView/Sources/Views/ViewModels/DefaultWebViewModel.swift index dadae799..c633771e 100644 --- a/TIWebView/Sources/Views/ViewModels/DefaultWebViewModel.swift +++ b/TIWebView/Sources/Views/ViewModels/DefaultWebViewModel.swift @@ -58,7 +58,8 @@ open class DefaultWebViewModel: NSObject, WebViewModel { let body = message.body as? [String: Any] return WebViewJSError(stringURL: body?[WebViewErrorConstants.errorUrl] as? String, name: body?[WebViewErrorConstants.errorName] as? String, - message: body?[WebViewErrorConstants.errorMessage] as? Int, + message: body?[WebViewErrorConstants.errorMessage] as? String, + lineNumber: body?[WebViewErrorConstants.errorLineNumber] as? Int, stackTrace: body?[WebViewErrorConstants.errorStack] as? String) } } diff --git a/project-scripts/push_to_podspecs.sh b/project-scripts/push_to_podspecs.sh index 217d9687..c53eec9f 100755 --- a/project-scripts/push_to_podspecs.sh +++ b/project-scripts/push_to_podspecs.sh @@ -22,7 +22,8 @@ ORDERED_PODSPECS="../TISwiftUtils/TISwiftUtils.podspec ../TIAppleMapUtils/TIAppleMapUtils.podspec ../TIGoogleMapUtils/TIGoogleMapUtils.podspec ../TIYandexMapUtils/TIYandexMapUtils.podspec -../TIEcommerce/TIEcommerce.podspec" +../TIEcommerce/TIEcommerce.podspec +../TIWebView/TIWebView.podspec" for podspec_path in ${ORDERED_PODSPECS}; do bundle exec pod repo push git@github.com:TouchInstinct/Podspecs ${podspec_path} --allow-warnings