Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(bridge): Safely JSON.Stringify circular json on log" #4539

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ const initBridge = (w: any): void => {
win.Ionic.WebView = IonicWebView;
};

const safeStringify = (value: any): string => {
const seen = new Set()
return JSON.stringify(value, (_k, v) => {
if (seen.has(v)) { return '...' }
if (typeof v === 'object') { seen.add(v) }
return v
})
}

const initLogger = (win: WindowCapacitor, cap: CapacitorInstance) => {
const BRIDGED_CONSOLE_METHODS: (keyof Console)[] = [
'debug',
Expand Down Expand Up @@ -280,11 +271,11 @@ const initBridge = (w: any): void => {
typeof c.dir === 'function'
);
};

const serializeConsoleMessage = (msg: any): string => {
if (typeof msg === 'object') {
try {
msg = safeStringify(msg);
msg = JSON.stringify(msg);
} catch (e) {
// ignore
}
Expand Down Expand Up @@ -371,7 +362,7 @@ const initBridge = (w: any): void => {
// android platform
postToNative = data => {
try {
win.androidBridge.postMessage(safeStringify(data));
win.androidBridge.postMessage(JSON.stringify(data));
} catch (e) {
win?.console?.error(e);
}
Expand Down Expand Up @@ -401,7 +392,7 @@ const initBridge = (w: any): void => {
url: url,
line: lineNo,
col: columnNo,
errorObject: safeStringify(err),
errorObject: JSON.stringify(err),
},
};

Expand Down