I am trying to inject my self directly into the source code.
We want to execute this script to remove a banner on google.com by injecting the javascript into the webview, but it's not working.
This is block of code we are trying to remove:
<mobile-promo jsname="EfADOe" jscontroller="sqHuef" jsaction="rcuQ6b:npT2md"> </mobile-promo>
This is what is not working:
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
let removeGoogleBottomBar = """
function removeDummy() {
var elem = document.getElementById('mobile-promo');
elem.parentNode.removeChild(elem);
return false;
}
removeDummy()
"""
webView.evaluateJavaScript(removeGoogleBottomBar)
}
Is there anything wrong with this approach to injecting javascript?