Is it possible to turn off location permission in WKWebView?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Is it possible to turn off location permission in WKWebView?



I am wondering if it is possible to stop WKWebView from showing the location permission prompt? ("website.com" Would Like To Use Your Current Location) I believe it is showing because the website contains a google map. I am not interested in preloading a location in its place like is shown in other SO questions. I simply don't want to use location in the WKWebView. Is there a way to stop the location permission prompt from appearing? I have tried injecting the following javascript but it doesn't work.


let contentController = WKUserContentController()

let scriptSource = "navigator.geolocation.getCurrentPosition = function(success, error, options) { // }; navigator.geolocation.watchPosition = function(success, error, options) { // }; navigator.geolocation.clearWatch = function(id) { // };"
let script = WKUserScript(source: scriptSource, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
contentController.addUserScript(script)

let config = WKWebViewConfiguration()
config.userContentController = contentController

webView = WKWebView(frame: .zero, configuration: config)
self.view = webView









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived