From d9dda826783dc91287916e444bac24d1b90b13f6 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 27 Sep 2022 11:51:44 +0530 Subject: [PATCH] Send message to inpage when extension revives (#15958) --- app/scripts/contentscript.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 1ae4167b3..dcaa6c59b 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -230,6 +230,8 @@ const setupExtensionStreams = () => { // connect "phishing" channel to warning system extensionPhishingStream = extensionMux.createStream('phishing'); extensionPhishingStream.once('data', redirectToPhishingWarning); + + notifyInpageOfExtensionStreamConnect(); }; /** Destroys all of the extension streams */ @@ -387,6 +389,26 @@ function logStreamDisconnectWarning(remoteLabel, error) { ); } +/** + * The function send message to inpage to notify it of extension stream connection + */ +function notifyInpageOfExtensionStreamConnect() { + window.postMessage( + { + target: INPAGE, // the post-message-stream "target" + data: { + // this object gets passed to obj-multiplex + name: PROVIDER, // the obj-multiplex channel name + data: { + jsonrpc: '2.0', + method: 'METAMASK_EXTENSION_STREAM_CONNECT', + }, + }, + }, + window.location.origin, + ); +} + /** * This function must ONLY be called in pump destruction/close callbacks. * Notifies the inpage context that streams have failed, via window.postMessage.