From cc7d85b25c87f6b7e03143659425afa86db1e491 Mon Sep 17 00:00:00 2001 From: jpuri Date: Sat, 24 Sep 2022 00:32:15 +0530 Subject: [PATCH 1/2] Send message to inpage when extension revives --- app/scripts/app-init.js | 21 ++++++++++++--------- app/scripts/contentscript.js | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/scripts/app-init.js b/app/scripts/app-init.js index 4ae247c5ba3a..37fb01b4258b 100644 --- a/app/scripts/app-init.js +++ b/app/scripts/app-init.js @@ -132,12 +132,15 @@ chrome.runtime.onMessage.addListener(() => { * MAIN world injection does not work properly via manifest * https://bugs.chromium.org/p/chromium/issues/detail?id=634381 */ -chrome.scripting.registerContentScripts([ - { - id: 'inpage', - matches: ['file://*/*', 'http://*/*', 'https://*/*'], - js: ['inpage.js'], - runAt: 'document_start', - world: 'MAIN', - }, -]); +// eslint-disable-next-line no-undef +self.addEventListener('install', () => { + chrome.scripting.registerContentScripts([ + { + id: 'inpage', + matches: ['file://*/*', 'http://*/*', 'https://*/*'], + js: ['inpage.js'], + runAt: 'document_start', + world: 'MAIN', + }, + ]); +}); diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 1ae4167b326c..dcaa6c59bc60 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. From 7562c9f2283f21baaf2dc01ccdb8cab6d3dfaa53 Mon Sep 17 00:00:00 2001 From: jpuri Date: Mon, 26 Sep 2022 15:08:27 +0530 Subject: [PATCH 2/2] fix --- app/scripts/app-init.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/scripts/app-init.js b/app/scripts/app-init.js index 37fb01b4258b..4ae247c5ba3a 100644 --- a/app/scripts/app-init.js +++ b/app/scripts/app-init.js @@ -132,15 +132,12 @@ chrome.runtime.onMessage.addListener(() => { * MAIN world injection does not work properly via manifest * https://bugs.chromium.org/p/chromium/issues/detail?id=634381 */ -// eslint-disable-next-line no-undef -self.addEventListener('install', () => { - chrome.scripting.registerContentScripts([ - { - id: 'inpage', - matches: ['file://*/*', 'http://*/*', 'https://*/*'], - js: ['inpage.js'], - runAt: 'document_start', - world: 'MAIN', - }, - ]); -}); +chrome.scripting.registerContentScripts([ + { + id: 'inpage', + matches: ['file://*/*', 'http://*/*', 'https://*/*'], + js: ['inpage.js'], + runAt: 'document_start', + world: 'MAIN', + }, +]);