|
1 |
| -export default () => { |
2 |
| - const cp = [] |
3 |
| - const stack = [[ai_manager, 0, cp]] |
4 |
| - const checked = new Set() |
5 |
| - while (stack.length > 0) { |
6 |
| - const [obj, key, parent] = stack.shift() |
7 |
| - if (obj instanceof Element) { |
8 |
| - continue |
9 |
| - } |
10 |
| - if (checked.has(obj)) { |
11 |
| - parent[key] = 'Recursive Object' |
12 |
| - } else if (obj === null) { |
13 |
| - parent[key] = null |
14 |
| - } else if (Array.isArray(obj)) { |
15 |
| - checked.add(obj) |
16 |
| - const arr = [] |
17 |
| - obj.forEach((v, i) => stack.push([v, i, arr])) |
18 |
| - parent[key] = arr |
19 |
| - } else if (typeof obj === 'object') { |
20 |
| - checked.add(obj) |
21 |
| - const o = {} |
22 |
| - const propNames = Object.getOwnPropertyNames(obj) |
23 |
| - propNames.sort() |
24 |
| - for (const key of propNames) { |
25 |
| - try { |
26 |
| - stack.push([obj[key], key, o]) |
27 |
| - } catch (e) { |
28 |
| - o[key] = 'error' |
29 |
| - } |
| 1 | +export default (page, option = {}) => { |
| 2 | + return page.evaluate(option => { |
| 3 | + const cp = [] |
| 4 | + const stack = [[ai_manager, 0, cp]] |
| 5 | + const checked = new Set() |
| 6 | + while (stack.length > 0) { |
| 7 | + const [obj, key, parent] = stack.shift() |
| 8 | + if (obj instanceof Element) { |
| 9 | + continue |
| 10 | + } |
| 11 | + if (option.ignoreProperties && option.ignoreProperties.includes(key)) { |
| 12 | + continue |
30 | 13 | }
|
31 |
| - let proto = Object.getPrototypeOf(obj) |
32 |
| - let cnt = 0 |
33 |
| - while (proto && cnt++ < 2) { |
34 |
| - const descriptors = Object.getOwnPropertyDescriptors(proto) |
35 |
| - const descriptorNames = Object.keys(descriptors) |
36 |
| - descriptorNames.sort() |
37 |
| - for (const key of descriptorNames) { |
38 |
| - const descriptor = descriptors[key] |
39 |
| - if (descriptor.get) { |
40 |
| - try { |
41 |
| - stack.push([obj[key], key, o]) |
42 |
| - } catch (e) { |
43 |
| - o[key] = 'error' |
| 14 | + if (checked.has(obj)) { |
| 15 | + parent[key] = 'Recursive Object' |
| 16 | + } else if (obj === null) { |
| 17 | + parent[key] = null |
| 18 | + } else if (Array.isArray(obj)) { |
| 19 | + checked.add(obj) |
| 20 | + const arr = [] |
| 21 | + obj.forEach((v, i) => stack.push([v, i, arr])) |
| 22 | + parent[key] = arr |
| 23 | + } else if (typeof obj === 'object') { |
| 24 | + checked.add(obj) |
| 25 | + const o = {} |
| 26 | + const propNames = Object.getOwnPropertyNames(obj) |
| 27 | + propNames.sort() |
| 28 | + for (const key of propNames) { |
| 29 | + try { |
| 30 | + stack.push([obj[key], key, o]) |
| 31 | + } catch (e) { |
| 32 | + o[key] = 'error' |
| 33 | + } |
| 34 | + } |
| 35 | + let proto = Object.getPrototypeOf(obj) |
| 36 | + let cnt = 0 |
| 37 | + while (proto && cnt++ < 2) { |
| 38 | + const descriptors = Object.getOwnPropertyDescriptors(proto) |
| 39 | + const descriptorNames = Object.keys(descriptors) |
| 40 | + descriptorNames.sort() |
| 41 | + for (const key of descriptorNames) { |
| 42 | + const descriptor = descriptors[key] |
| 43 | + if (descriptor.get) { |
| 44 | + try { |
| 45 | + stack.push([obj[key], key, o]) |
| 46 | + } catch (e) { |
| 47 | + o[key] = 'error' |
| 48 | + } |
44 | 49 | }
|
45 | 50 | }
|
| 51 | + proto = Object.getPrototypeOf(proto) |
46 | 52 | }
|
47 |
| - proto = Object.getPrototypeOf(proto) |
| 53 | + parent[key] = o |
| 54 | + } else if (typeof obj === 'function') { |
| 55 | + parent[key] = obj.toString() |
| 56 | + } else { |
| 57 | + parent[key] = obj |
48 | 58 | }
|
49 |
| - parent[key] = o |
50 |
| - } else if (typeof obj === 'function') { |
51 |
| - parent[key] = obj.toString() |
52 |
| - } else { |
53 |
| - parent[key] = obj |
54 | 59 | }
|
55 |
| - } |
56 |
| - return JSON.parse(JSON.stringify(cp[0])) |
| 60 | + return JSON.parse(JSON.stringify(cp[0])) |
| 61 | + }, option) |
57 | 62 | }
|
0 commit comments