Skip to content

Commit 1b61937

Browse files
authored
Merge pull request #29140 from brave/ios-js-pref-fix-1.79.x
[iOS] Reset `javaScriptEnabled` preference correctly between navigations (uplift to 1.79.x)
2 parents 30551ba + 77b3774 commit 1b61937

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

chromium_src/ios/web/navigation/crw_wk_navigation_handler.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ - (void)webView:(WKWebView*)webView
4040
// Only ever update it to false
4141
preferences.allowsContentJavaScript = false;
4242
}
43+
44+
if (@available(iOS 18, *)) {
45+
} else {
46+
#pragma clang diagnostic push
47+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
48+
// In prior versions of iOS,
49+
// `WKWebpagePreferences.allowsContentJavaScript` does not work
50+
// correctly in all cases:
51+
// https://github.com/brave/brave-ios/issues/8585
52+
webView.configuration.preferences.javaScriptEnabled =
53+
preferences.allowsContentJavaScript;
54+
#pragma clang diagnostic pop
55+
}
56+
4357
if (policy == WKNavigationActionPolicyAllow) {
4458
// Check if we want to explicitly block universal links
4559
bool forceBlockUniversalLinks = brave::ShouldBlockUniversalLinks(

ios/brave-ios/Sources/Web/WebKit/TabWKNavigationHandler.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,13 @@ class TabWKNavigationHandler: NSObject, WKNavigationDelegate {
116116
if let delegate = tab.delegate,
117117
delegate.tab(tab, shouldBlockJavaScriptForRequest: navigationAction.request)
118118
{
119-
// Due to a bug in iOS WKWebpagePreferences.allowsContentJavaScript does NOT work!
120-
// https://github.com/brave/brave-ios/issues/8585
121-
//
122-
// However, the deprecated API WKWebViewConfiguration.preferences.javaScriptEnabled DOES work!
123-
// Even though `configuration` is @NSCopying, somehow this actually updates the preferences LIVE!!
124-
// This follows the same behaviour as Safari
125-
//
126-
// - Brandon T.
127-
//
128119
preferences.allowsContentJavaScript = false
129-
webView.configuration.preferences.javaScriptEnabled = false
120+
}
121+
122+
if #unavailable(iOS 18.0) {
123+
// In prior versions of iOS, `WKWebpagePreferences.allowsContentJavaScript` does not work
124+
// correctly in all cases: https://github.com/brave/brave-ios/issues/8585
125+
webView.configuration.preferences.javaScriptEnabled = preferences.allowsContentJavaScript
130126
}
131127

132128
// Downloads

0 commit comments

Comments
 (0)