Commit 2b08ffe6 authored by Robert Knight's avatar Robert Knight

Capture and forward errors during port request message handling

Capture errors that happen while handling port requests in `PortProvider#listen`
and forward them to the sidebar, so we can gain visibility into them.
parent 59d2f213
import { TinyEmitter } from 'tiny-emitter'; import { TinyEmitter } from 'tiny-emitter';
import { captureErrors } from './frame-error-capture';
import { ListenerCollection } from './listener-collection'; import { ListenerCollection } from './listener-collection';
import { isMessageEqual, isSourceWindow } from './port-util'; import { isMessageEqual, isSourceWindow } from './port-util';
...@@ -146,10 +147,9 @@ export class PortProvider { ...@@ -146,10 +147,9 @@ export class PortProvider {
* Initiate the listener of port requests by other frames. * Initiate the listener of port requests by other frames.
*/ */
listen() { listen() {
this._listeners.add(window, 'message', messageEvent => { /** @param {Event} event */
const { data, origin, source } = /** @type {MessageEvent} */ ( const handleRequest = event => {
messageEvent const { data, origin, source } = /** @type {MessageEvent} */ (event);
);
if (!isSourceWindow(source)) { if (!isSourceWindow(source)) {
return; return;
...@@ -201,7 +201,13 @@ export class PortProvider { ...@@ -201,7 +201,13 @@ export class PortProvider {
} else if (frame2 === 'host') { } else if (frame2 === 'host') {
this._emitter.emit('frameConnected', frame1, messageChannel.port2); this._emitter.emit('frameConnected', frame1, messageChannel.port2);
} }
}); };
this._listeners.add(
window,
'message',
captureErrors(handleRequest, 'Handling port request')
);
} }
destroy() { destroy() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment