Skip to content

Commit f233930

Browse files
fix(extension): improve Dapp API injection performance (#1576)
1 parent 2e1fad5 commit f233930

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

apps/browser-extension-wallet/manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
"extension_pages": "default-src 'self' $LOCALHOST_DEFAULT_SRC; frame-src https://connect.trezor.io/ https://www.youtube-nocookie.com; script-src 'self' 'wasm-unsafe-eval' $LOCALHOST_SCRIPT_SRC; font-src 'self' https://use.typekit.net; object-src 'self'; connect-src $BLOCKFROST_URLS $CARDANO_SERVICES_URLS $CARDANO_WS_SERVER_URLS $SENTRY_URL https://coingecko.live-mainnet.eks.lw.iog.io https://muesliswap.live-mainnet.eks.lw.iog.io $LOCALHOST_CONNECT_SRC $POSTHOG_HOST https://use.typekit.net data:; style-src * 'unsafe-inline'; img-src * data:;"
2323
},
2424
"content_scripts": [
25+
{
26+
"matches": ["http://*/*", "https://*/*", "file://*/*"],
27+
"js": ["./js/inject.js"],
28+
"run_at": "document_start",
29+
"world": "MAIN",
30+
"all_frames": true
31+
},
2532
{
2633
"matches": ["http://*/*", "https://*/*", "file://*/*"],
2734
"js": ["./js/content.js"],
Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { runtime } from 'webextension-polyfill';
2-
import {
3-
cip30,
4-
consumeRemoteApi,
5-
MessengerDependencies,
6-
runContentScriptMessageProxy
7-
} from '@cardano-sdk/web-extension';
2+
import { consumeRemoteApi, MessengerDependencies, runContentScriptMessageProxy } from '@cardano-sdk/web-extension';
83
import { consumeRemoteAuthenticatorApi, consumeRemoteWalletApi } from './api-consumers';
9-
import { laceFeaturesApiProperties, LACE_FEATURES_CHANNEL } from './injectUtil';
4+
import { LACE_FEATURES_CHANNEL, laceFeaturesApiProperties } from './injectUtil';
105

116
// Disable logging in production for performance & security measures
127
if (process.env.USE_DAPP_CONNECTOR === 'true') {
138
console.info('initializing content script');
149

15-
const initializeContentScript = (
16-
{ injectedScriptSrc, walletName }: cip30.InitializeContentScriptProps,
17-
dependencies: MessengerDependencies
18-
) => {
10+
const initializeContentScript = (walletName: string, dependencies: MessengerDependencies) => {
1911
const apis = [
2012
consumeRemoteAuthenticatorApi({ walletName }, dependencies),
2113
consumeRemoteWalletApi({ walletName }, dependencies),
@@ -27,19 +19,9 @@ if (process.env.USE_DAPP_CONNECTOR === 'true') {
2719
dependencies
2820
)
2921
];
30-
const proxy = runContentScriptMessageProxy(apis, dependencies.logger);
3122

32-
const script = document.createElement('script');
33-
script.async = false;
34-
script.src = injectedScriptSrc;
35-
script.addEventListener('load', () => script.remove());
36-
(document.head || document.documentElement).append(script);
37-
38-
return proxy;
23+
return runContentScriptMessageProxy(apis, dependencies.logger);
3924
};
4025

41-
initializeContentScript(
42-
{ injectedScriptSrc: runtime.getURL('./js/inject.js'), walletName: process.env.WALLET_NAME },
43-
{ logger: console, runtime }
44-
);
26+
initializeContentScript(process.env.WALLET_NAME, { logger: console, runtime });
4527
}

0 commit comments

Comments
 (0)