Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Ignore legacy `publicConfig` stream in `createExternalExtensionProvider` to prevent `ObjectMultiplex - orphaned data for stream "publicConfig"` warnings ([#429](https://github.com/MetaMask/providers/pull/429))

## [22.1.1]

### Changed
Expand Down
17 changes: 17 additions & 0 deletions src/extension-provider/createExternalExtensionProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ describe('createExternalExtensionProvider', () => {
expect(global.chrome.runtime.connect).toHaveBeenCalledWith('foobar');
});

it('ignores messages for the legacy publicConfig stream', async () => {
const consoleWarnSpy = jest.spyOn(globalThis.console, 'warn');
const { port } = await getInitializedProvider();

port.notify('publicConfig', {
jsonrpc: '2.0',
method: 'metamask_chainChanged',
params: { chainId: '0x1', networkVersion: '1' },
});
// Wait for the message to propagate through the stream pipeline.
await new Promise((resolve) => setTimeout(resolve, 10));

expect(consoleWarnSpy).not.toHaveBeenCalledWith(
'ObjectMultiplex - orphaned data for stream "publicConfig"',
);
});

describe('RPC warnings', () => {
const warnings = [
{
Expand Down
10 changes: 10 additions & 0 deletions src/extension-provider/createExternalExtensionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { getDefaultExternalMiddleware } from '../utils';

const browser = detect();

/**
* The name of the legacy public config substream. The MetaMask extension
* still writes to this stream, but the provider no longer uses it.
*/
const LegacyPublicConfigStreamName = 'publicConfig';

export type ExtensionType = 'stable' | 'flask' | 'beta' | string;

/**
Expand All @@ -32,6 +38,10 @@ export function createExternalExtensionProvider(
const pluginStream = new PortStream(metamaskPort);
const streamName = MetaMaskInpageProviderStreamName;
const mux = new ObjectMultiplex();
// The wallet still writes to the legacy `publicConfig` stream. Ignore it
// to avoid "ObjectMultiplex - orphaned data" warnings, mirroring how the
// MetaMask extension contentscript ignores legacy streams.
mux.ignoreStream(LegacyPublicConfigStreamName);
pipeline(pluginStream, mux, pluginStream, (error: Error | null) => {
let warningMsg = `Lost connection to "${streamName}".`;
if (error?.stack) {
Expand Down