Skip to content

Commit 48de03d

Browse files
authored
Merge pull request #272 from codeitcodes/patch-1
Patch 1
2 parents 8194597 + cfdf286 commit 48de03d

File tree

2 files changed

+109
-76
lines changed

2 files changed

+109
-76
lines changed

live-view/extensions/mobile-console/logger.js

Lines changed: 108 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -203,107 +203,140 @@ let logger = {
203203
// remove the first empty item (because of how split works)
204204
stack.shift();
205205

206-
} else {
206+
} else if (stack) {
207207

208208
// split stack
209209
stack = stack.split('\n');
210210

211211
}
212212

213213

214-
if (!isLoggerEval) {
215-
216-
// replace absolute URLs with relative URLs in stack
217-
218-
// get origin URL
219-
const location = logger.cW.location;
220-
const originURL = location.origin + location.pathname;
221-
const indexURL = originURL + location.search;
222-
223-
if (!isSafari) {
224-
225-
stack.forEach((entry, index) => {
226-
227-
// replace index URLs
228-
entry = entry.replaceAll(indexURL, '(index)');
229-
230-
// remove absolute URLs' origin
231-
entry = entry.replaceAll(originURL, '');
232-
233-
stack[index] = entry;
234-
235-
});
214+
if (stack) {
236215

237-
} else {
216+
if (!isLoggerEval) {
238217

239-
stack.forEach((entry, index) => {
218+
// replace absolute URLs with relative URLs in stack
240219

241-
const entryURLIndex = entry.indexOf('@');
220+
// get origin URL
221+
const location = logger.cW.location;
222+
const originURL = location.origin + location.pathname;
223+
const indexURL = originURL + location.search;
224+
225+
if (!isSafari) {
226+
227+
stack.forEach((entry, index) => {
228+
229+
// replace index URLs
230+
entry = entry.replaceAll(indexURL, '(index)');
231+
232+
// remove absolute URLs' origin
233+
entry = entry.replaceAll(originURL, '');
234+
235+
stack[index] = entry;
236+
237+
});
242238

243-
let entryContext = entry.slice(0, entryURLIndex);
244-
let entryURL = entry.slice(entryURLIndex + 1);
239+
} else {
245240

246-
if (entryContext === 'global code') entryContext = '';
241+
stack.forEach((entry, index) => {
247242

248-
// if the context is eval code
249-
// and it has no URL
250-
if (entryContext === 'eval code' && entryURL === '') {
243+
const entryURLIndex = entry.indexOf('@');
251244

252-
// add the error's line number and column number
253-
// to the URL
254-
entryURL = '<anonymous>:' + error.line + ':' + error.column;
245+
let entryContext = entry.slice(0, entryURLIndex);
246+
let entryURL = entry.slice(entryURLIndex + 1);
255247

256-
}
248+
if (entryContext === 'global code') entryContext = '';
249+
250+
// if the context is eval code
251+
// and it has no URL
252+
if (entryContext === 'eval code' && entryURL === '') {
253+
254+
// add the error's line number and column number
255+
// to the URL
256+
entryURL = '<anonymous>:' + error.line + ':' + error.column;
257+
258+
}
259+
260+
261+
// replace index URLs
262+
entryURL = entryURL.replaceAll(indexURL, '(index)');
263+
entryContext = entryContext.replaceAll(indexURL, '(index)');
264+
265+
// remove absolute URLs' origin
266+
entryURL = entryURL.replaceAll(originURL, '');
267+
entryContext = entryContext.replaceAll(originURL, '');
268+
269+
270+
// if both entry URL and entry context exist,
271+
// surround the entry URL with brackets
272+
if (entryURL !== '' && entryContext !== '') {
273+
274+
entryURL = ' (' + entryURL + ')';
275+
276+
}
277+
278+
// restructure entry
279+
stack[index] = entryContext + entryURL;
280+
281+
});
257282

283+
}
284+
285+
} else {
286+
287+
if (!isSafari) {
258288

259-
// replace index URLs
260-
entryURL = entryURL.replaceAll(indexURL, '(index)');
261-
entryContext = entryContext.replaceAll(indexURL, '(index)');
289+
// parses:
290+
// 'eval (eval at run (logger.js:91:14), <anonymous>:1:13)'
291+
// into:
292+
// '<anonymous>:1:13'
262293

263-
// remove absolute URLs' origin
264-
entryURL = entryURL.replaceAll(originURL, '');
265-
entryContext = entryContext.replaceAll(originURL, '');
294+
const evalInfo = stack[0].slice('eval ('.length, -(')'.length));
266295

296+
const evalStack = evalInfo.split(', ')[1];
267297

268-
// if both entry URL and entry context exist,
269-
// surround the entry URL with brackets
270-
if (entryURL !== '' && entryContext !== '') {
271-
272-
entryURL = ' (' + entryURL + ')';
273-
274-
}
298+
stack = [evalStack];
299+
300+
} else {
301+
302+
// the error's line number and column number
303+
// aren't available in the stack on Safari,
304+
// so we need to get them from the Error object
275305

276-
// restructure entry
277-
stack[index] = entryContext + entryURL;
306+
stack = ['<anonymous>:' + error.line + ':' + error.column];
278307

279-
});
308+
}
280309

281310
}
282311

283-
} else {
312+
} else if (isSafari) {
284313

285-
if (!isSafari) {
286-
287-
// parses:
288-
// 'eval (eval at run (logger.js:91:14), <anonymous>:1:13)'
289-
// into:
290-
// '<anonymous>:1:13'
291-
292-
const evalInfo = stack[0].slice('eval ('.length, -(')'.length));
293-
294-
const evalStack = evalInfo.split(', ')[1];
295-
296-
stack = [evalStack];
297-
298-
} else {
299-
300-
// the error's line number and column number
301-
// aren't available in the stack on Safari,
302-
// so we need to get them from the Error object
303-
304-
stack = ['<anonymous>:' + error.line + ':' + error.column];
305-
306-
}
314+
// the error's line number and column number
315+
// sometimes aren't available in the stack on Safari,
316+
// so we need to get them from the Error object
317+
318+
319+
// replace absolute URLs with relative URLs in stack
320+
321+
// get origin URL
322+
const location = logger.cW.location;
323+
const originURL = location.origin + location.pathname;
324+
const indexURL = originURL + location.search;
325+
326+
let entryURL = error.sourceURL;
327+
328+
// replace index URLs
329+
entryURL = entryURL.replaceAll(indexURL, '(index)');
330+
331+
// remove absolute URLs' origin
332+
entryURL = entryURL.replaceAll(originURL, '');
333+
334+
335+
const line = error.line ?? 0;
336+
const column = error.column ?? 0;
337+
338+
// save entry in stack
339+
stack = [entryURL + ':' + line + ':' + column];
307340

308341
}
309342

service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
// update worker name when updating cached files
3-
const WORKER_NAME = 'codeit-worker-v764';
3+
const WORKER_NAME = 'codeit-worker-v765';
44

55

66
self.importScripts('/worker/client-channel.js');

0 commit comments

Comments
 (0)