1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Send message to inpage when extension revives (#15958)

This commit is contained in:
Jyoti Puri 2022-09-27 11:51:44 +05:30 committed by GitHub
parent 24a3156a2b
commit d9dda82678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.