mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
MV3: support Service Worker restart for phishing warning pages (#16488)
* dapp: fix phishing Could not establish connection * dapp: only call phishing keep alive timer on load Co-authored-by: Jyoti Puri <jyotipuri@gmail.com> Co-authored-by: Jyoti Puri <jyotipuri@gmail.com>
This commit is contained in:
parent
0841c1df4f
commit
2966b9f665
@ -6,10 +6,7 @@ import PortStream from 'extension-port-stream';
|
||||
import { obj as createThoughStream } from 'through2';
|
||||
|
||||
import { EXTENSION_MESSAGES, MESSAGE_TYPE } from '../../shared/constants/app';
|
||||
import {
|
||||
checkForLastError,
|
||||
checkForLastErrorAndWarn,
|
||||
} from '../../shared/modules/browser-runtime.utils';
|
||||
import { checkForLastError } from '../../shared/modules/browser-runtime.utils';
|
||||
import { isManifestV3 } from '../../shared/modules/mv3.utils';
|
||||
import shouldInjectProvider from '../../shared/modules/provider-injection';
|
||||
|
||||
@ -141,11 +138,7 @@ function setupPhishingPageStreams() {
|
||||
});
|
||||
|
||||
if (isManifestV3) {
|
||||
phishingPageStream.on('data', ({ data: { method } }) => {
|
||||
if (!IGNORE_INIT_METHODS_FOR_KEEP_ALIVE.includes(method)) {
|
||||
runWorkerKeepAliveInterval();
|
||||
}
|
||||
});
|
||||
runWorkerKeepAliveInterval();
|
||||
}
|
||||
|
||||
// create and connect channel muxers
|
||||
@ -220,13 +213,25 @@ const destroyPhishingExtStreams = () => {
|
||||
* so that streams may be re-established later the phishing extension port is reconnected.
|
||||
*/
|
||||
const onDisconnectDestroyPhishingStreams = () => {
|
||||
checkForLastErrorAndWarn();
|
||||
const err = checkForLastError();
|
||||
|
||||
phishingExtPort.onDisconnect.removeListener(
|
||||
onDisconnectDestroyPhishingStreams,
|
||||
);
|
||||
|
||||
destroyPhishingExtStreams();
|
||||
|
||||
/**
|
||||
* If an error is found, reset the streams. When running two or more dapps, resetting the service
|
||||
* worker may cause the error, "Error: Could not establish connection. Receiving end does not
|
||||
* exist.", due to a race-condition. The disconnect event may be called by runtime.connect which
|
||||
* may cause issues. We suspect that this is a chromium bug as this event should only be called
|
||||
* once the port and connections are ready. Delay time is arbitrary.
|
||||
*/
|
||||
if (err) {
|
||||
console.warn(`${err} Resetting the phishing streams.`);
|
||||
setTimeout(setupPhishingExtStreams, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user