Skip to content

Commit

Permalink
fix for ios and macos pichillilorenzo#1738
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo authored and Gurtaj Singh committed Dec 5, 2023
1 parent 33e42bb commit cb13a85
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions ios/Classes/PluginScriptsJS/ConsoleLogJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ let CONSOLE_LOG_JS_PLUGIN_SCRIPT = PluginScript(
let CONSOLE_LOG_JS_SOURCE = """
(function(console) {
function _callHandler(oldLog, args) {
var message = '';
for (var i in args) {
try {
message += message === '' ? args[i] : ' ' + args[i];
} catch(ignored) {}
}
var _windowId = \(WINDOW_ID_VARIABLE_JS_SOURCE);
window.webkit.messageHandlers[oldLog].postMessage({'message': message, '_windowId': _windowId});
}
var oldLogs = {
'consoleLog': console.log,
'consoleDebug': console.debug,
Expand All @@ -33,24 +44,7 @@ let CONSOLE_LOG_JS_SOURCE = """
(function(oldLog) {
console[oldLog.replace('console', '').toLowerCase()] = function() {
oldLogs[oldLog].apply(null, arguments);
var args = arguments;
// on iOS, for some reason, accessing the arguments object synchronously can throw some errors, such as "TypeError"
// see https://github.com/pichillilorenzo/flutter_inappwebview/issues/776
setTimeout(function() {
var message = '';
for (var i in args) {
if (message == '') {
message += args[i];
}
else {
message += ' ' + args[i];
}
}
var _windowId = \(WINDOW_ID_VARIABLE_JS_SOURCE);
window.webkit.messageHandlers[oldLog].postMessage({'message': message, '_windowId': _windowId});
});
_callHandler(oldLog, arguments);
}
})(k);
}
Expand Down

0 comments on commit cb13a85

Please sign in to comment.