Merge pull request #740 from kiwix/feature/215-make-webview-inspectable

Make webView inspectable / debuggable
This commit is contained in:
rgaudin 2024-04-26 09:18:36 +00:00 committed by GitHub
commit 2465f27e10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,26 @@
// This file is part of Kiwix for iOS & macOS.
//
// Kiwix is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// any later version.
//
// Kiwix is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
import Foundation
extension Bundle {
var isProduction: Bool {
#if DEBUG
false
#else
appStoreReceiptURL?.path.contains("sandboxReceipt") == true
#endif
}
}

View File

@ -96,6 +96,9 @@ final class BrowserViewModel: NSObject, ObservableObject,
init(tabID: NSManagedObjectID? = nil) {
self.tabID = tabID
webView = WKWebView(frame: .zero, configuration: WebViewConfiguration())
if !Bundle.main.isProduction, #available(iOS 16.4, macOS 13.3, *) {
webView.isInspectable = true
}
// Bookmark fetching:
bookmarkFetchedResultsController = NSFetchedResultsController(
fetchRequest: Bookmark.fetchRequest(), // initially empty
@ -402,6 +405,9 @@ final class BrowserViewModel: NSObject, ObservableObject,
let configuration = UIContextMenuConfiguration(
previewProvider: {
let webView = WKWebView(frame: .zero, configuration: WebViewConfiguration())
if !Bundle.main.isProduction, #available(iOS 16.4, *) {
webView.isInspectable = true
}
webView.load(URLRequest(url: url))
return WebViewController(webView: webView)
},