1 | const unmirror = require('chrome-unmirror');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | module.exports = function chromeOut(log, options, Runtime) {
|
7 | Runtime.exceptionThrown((exception) => {
|
8 | if (!options.ignoreExceptions) {
|
9 | log.error('[chrome-exception]', exception);
|
10 | }
|
11 | });
|
12 |
|
13 | Runtime.consoleAPICalled(({ type, args }) => {
|
14 | if (options.ignoreConsole) {
|
15 | return;
|
16 | }
|
17 |
|
18 | if (type === 'warning') {
|
19 |
|
20 | type = 'warn';
|
21 | }
|
22 |
|
23 |
|
24 | const data = [];
|
25 | const unknownTypes = [
|
26 | 'assert',
|
27 | 'clear',
|
28 | 'count',
|
29 | 'dir',
|
30 | 'dirxmnl',
|
31 | 'endGroup',
|
32 | 'profile',
|
33 | 'profileEnd',
|
34 | 'startGroup',
|
35 | 'startGroupCollapsed',
|
36 | 'table',
|
37 | 'timeEnd',
|
38 | 'trace'
|
39 | ];
|
40 |
|
41 | for (const arg of args) {
|
42 | if (arg.type === 'string') {
|
43 | data.push(arg.value);
|
44 | } else {
|
45 | data.push(unmirror(arg));
|
46 | }
|
47 | }
|
48 |
|
49 | if (unknownTypes.includes(type)) {
|
50 |
|
51 | type = 'log';
|
52 | }
|
53 |
|
54 |
|
55 | console[type].apply(this, data);
|
56 | });
|
57 | };
|