| 83 | } |
| 84 | |
| 85 | private static wrap<T extends Object>(handler: T): T { |
| 86 | return new Proxy(handler, { |
| 87 | get(target, prop) { |
| 88 | if (typeof target[prop] === 'function') { |
| 89 | return (params, message: ProtocolMessage) => { |
| 90 | try { |
| 91 | // console.warn('[incoming]', { |
| 92 | // id: message.id, |
| 93 | // method: message.method, |
| 94 | // params, |
| 95 | // message, |
| 96 | // }); |
| 97 | const res = target[prop](params, message); |
| 98 | ProtocolWrapper.sendResponseToDevtools(message.id, res); |
| 99 | return res; |
| 100 | } catch (err) { |
| 101 | console.error(err); |
| 102 | } |
| 103 | }; |
| 104 | } |
| 105 | }, |
| 106 | }) as T; |
| 107 | } |
| 108 | } |