-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix posts page crashes evaluating JavaScript (#1173)
* Move remaining WKWebView evaluateJavaScript calls to async-await. * Make a non-crashing async-await version of evaluateJavaScript(_:). * Remove iOS 13- fallback menu from posts page.
- Loading branch information
Showing
5 changed files
with
141 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// WKWebView+eval.swift | ||
// | ||
// Copyright 2015 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app | ||
|
||
import WebKit | ||
|
||
extension WKWebView { | ||
/** | ||
Evaluates the specified JavaScript string. | ||
The async-await version of `evaluateJavaScript(_:)` in the overlay assumes a non-`nil` result of evaluating `javaScript`. This async-await version does not make that assumption. | ||
*/ | ||
@discardableResult | ||
func eval(_ javaScript: String) async throws -> Any? { | ||
try await withCheckedThrowingContinuation { continuation in | ||
evaluateJavaScript(javaScript, completionHandler: { result, error in | ||
if let error { | ||
continuation.resume(throwing: error) | ||
} else { | ||
continuation.resume(returning: result) | ||
} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.