Skip to content

Conversation

@jiexi
Copy link
Contributor

@jiexi jiexi commented Feb 5, 2025

Description

  • Exposes the Multichain API over window.postMessage for Firefox
  • Enables Flask e2e Multichain API tests for Firefox

Open in GitHub Codespaces

Related issues

Test Dapp: MetaMask/test-dapp-multichain#48

Manual testing steps

yarn start:flask:mv2
In a non-chromium browser, i.e. Firefox

Without helper packages

window.addEventListener('message', (event) => {
  const {
    target,
    data
  } = event.data;
  if (
    target !== "metamask-inpage" ||
    data?.name !== 'metamask-multichain-provider'
  ) {
    return;
  }
  console.log(data.data)
})

const caipPostMessage = (data) => {
  window.postMessage({
    target: 'metamask-contentscript',
    data: {
      name: 'metamask-multichain-provider',
      data
    }
  }, location.origin)
}

caipPostMessage({
    jsonrpc: '2.0',
    method: 'wallet_createSession',
    params: {
      optionalScopes: {}
    }
})

With helper packages (psuedo-ish code)

import { WindowPostMessageStream } from '@metamask/post-message-stream';
import ObjectMultiplex from '@metamask/object-multiplex';
import { pipeline } from 'readable-stream';

  const metamaskStream = new WindowPostMessageStream({
    name: INPAGE,
    target: CONTENT_SCRIPT,
  });

  const metamaskMux = new ObjectMultiplex(metamaskStream)
  const caipStream =  window.metamaskMux.createStream('metamask-provider-caip')

  pipeline(metamaskMux, metamaskStream, metamaskMux, (err) => {
    console.log({err})
  });

caipStream.on('data', console.log) 

caipStream.write({jsonrpc: '2.0', method: 'wallet_createSession', params:{optionalScopes: {}} })

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

metamaskbot and others added 30 commits January 16, 2025 17:34
…al.tsx

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
…29724)

-- test: multichain test dapp e2e tests for password locked extension
# Conflicts:
#	lavamoat/browserify/beta/policy.json
#	lavamoat/browserify/flask/policy.json
#	lavamoat/browserify/main/policy.json
#	lavamoat/browserify/mmi/policy.json
#	package.json
#	yarn.lock
jiexi added 2 commits April 8, 2025 09:39
…postMessage-stream-non-chromium' into jl/mmp-3725/caip-multichain-add-postMessage-stream-non-chromium
@metamaskbot
Copy link
Collaborator

Builds ready [ca74228]
UI Startup Metrics (1235 ± 78 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1235112615337812811388
load10779461361791178991
domContentLoaded10719411356791229993
domInteractive17136261629
firstPaint7601301365421235990
backgroundConnect116516910
firstReactRender21155681940
getState12538778
initialActions001000
loadScripts821693110777864927
setupStore8523379
WebpackHomeuiStartup21201662246519122582372
load16591283201117617621938
domContentLoaded16541279200517517571932
domInteractive171269121458
firstPaint172643916524590
backgroundConnect3111403393552
firstReactRender164543821136197
getState1341631779
initialActions315135
loadScripts16451262198017217491909
setupStore27639758378
FirefoxBrowserifyHomeuiStartup13331141177712214031575
load12021027165012012631442
domContentLoaded12011027164912012631442
domInteractive10638236308998
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect2416137132338
firstReactRender21184742131
getState7342578
initialActions001001
loadScripts11791010162011912281419
setupStore6428367
WebpackHomeuiStartup1516135918699115581682
load1302116015868313561452
domContentLoaded1301116015868313561452
domInteractive9544170229098
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect26197482746
firstReactRender36305353849
getState9531689
initialActions001011
loadScripts1277113815658313271432
setupStore8528389

@metamaskbot
Copy link
Collaborator

Builds ready [9697f0d]
UI Startup Metrics (1210 ± 49 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1210109913474912341296
load10549301147491131995
domContentLoaded10489211142491136991
domInteractive17133341729
firstPaint6701341148417253989
backgroundConnect7415279
firstReactRender20147992039
getState13549979
initialActions001001
loadScripts80867990548837887
setupStore8426378
WebpackHomeuiStartup21341739269617422512390
load16861296214715817551995
domContentLoaded16771291214315417421986
domInteractive171264111350
firstPaint167644287027587
backgroundConnect36939657349
firstReactRender163523931086088
getState1743024059
initialActions316135
loadScripts16691289214114617401924
setupStore2463054579
FirefoxBrowserifyHomeuiStartup13751168176210514461561
load12331038163610513041413
domContentLoaded12331038163610513041413
domInteractive10339246348995
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect2113126152030
firstReactRender23195252327
getState7449589
initialActions001001
loadScripts12131023162210712861400
setupStore6437467
WebpackHomeuiStartup15481374200211816441753
load13351188169110514041534
domContentLoaded13351188169110514041534
domInteractive10265213219297
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect21148182235
firstReactRender34295553645
getState8429489
initialActions002111
loadScripts13171164166910513881513
setupStore1152982979

@jiexi
Copy link
Contributor Author

jiexi commented Apr 15, 2025

this PR needs to be updated with new test dapp release MetaMask/test-dapp-multichain#54

@metamaskbot
Copy link
Collaborator

❌ API Spec Test Failed. View the report here.

@jiexi jiexi added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Apr 16, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [f0c8812]
UI Startup Metrics (1223 ± 67 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1223110214656712551373
load106296612906411041185
domContentLoaded105596212206110961175
domInteractive18136161730
firstPaint80592122740110861182
backgroundConnect84838712
firstReactRender21155472135
getState1454592032
initialActions001001
loadScripts81372497658850910
setupStore75162710
WebpackHomeuiStartup21541741250116622892392
load16601343195212717621850
domContentLoaded16531340194212617561840
domInteractive151156101348
firstPaint1866546472221326
backgroundConnect309256342968
firstReactRender21655399120332362
getState164261301429
initialActions318136
loadScripts16481338192012617521838
setupStore207284282034
FirefoxBrowserifyHomeuiStartup13461161161810214121544
load12021035148410512851389
domContentLoaded12021034148310512841389
domInteractive1053823734124171
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect19126361927
firstReactRender21193122226
getState7430479
initialActions001001
loadScripts11851017146510512671373
setupStore841961967
WebpackHomeuiStartup16081387206715416801976
load13721166182814314251725
domContentLoaded13721164182814314251725
domInteractive933532344100164
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect241581102541
firstReactRender38295754049
getState1053261028
initialActions102111
loadScripts13501149181314214061699
setupStore95313912
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 400 Bytes (0.01%)
  • ui: 0 Bytes (0%)
  • common: 0 Bytes (0%)

@adonesky1 adonesky1 enabled auto-merge April 16, 2025 20:30
@adonesky1 adonesky1 added this pull request to the merge queue Apr 16, 2025
Merged via the queue into main with commit 12f1417 Apr 16, 2025
169 checks passed
@adonesky1 adonesky1 deleted the jl/mmp-3725/caip-multichain-add-postMessage-stream-non-chromium branch April 16, 2025 21:13
@github-actions github-actions bot locked and limited conversation to collaborators Apr 16, 2025
@metamaskbot metamaskbot added the release-12.18.0 Issue or pull request that will be included in release 12.18.0 label Apr 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-12.18.0 Issue or pull request that will be included in release 12.18.0 team-wallet-api-platform-deprecated DEPRECATED: please use "team-wallet-integrations" instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants