This repository was archived by the owner on Mar 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
fixed: check the routing of method and route it to flow if connected. #1044
Open
zzggo
wants to merge
6
commits into
dev
Choose a base branch
from
1040-bug-kitty-punch-referral-code-transaction-cant-open-popup
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a7e9252
fixed: check the routing of method and route it to flow if connected.
zzggo cf7725f
refactor: update manifest permissions and implement content script in…
tombeckenham 6feecec
fixed: connection conflict
zzggo 57f50a3
refactor: enhance message handling and security in PostMessage class
tombeckenham 399138c
Add template to serve for EIP-6963 testing
tombeckenham f5c56fa
Merge branch 'dev' into 1040-bug-kitty-punch-referral-code-transactio…
tombeckenham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,6 @@ const flowContext = flow | |
| mapMethod !== 'walletWatchAsset' && | ||
| mapMethod !== 'walletConnect' && | ||
| mapMethod !== 'walletDisconnect' && | ||
| mapMethod !== 'walletConnect' && | ||
| !Reflect.getMetadata('SAFE', providerController, mapMethod) | ||
| ) { | ||
| if (!permissionService.hasPermission(origin) || !(await Wallet.isUnlocked())) { | ||
|
Comment on lines
60
to
66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition check for |
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import { consoleError, consoleLog } from '@/shared/utils/console-log'; | ||
|
|
||
| /* | ||
| * This content script is injected programmatically because | ||
| * MAIN world injection does not work properly via manifest | ||
| * https://bugs.chromium.org/p/chromium/issues/detail?id=634381 | ||
| */ | ||
|
|
||
| class ContentScriptInjectionService { | ||
| private registeredScripts = new Set<string>(); | ||
|
|
||
| init = async () => { | ||
| // Register message bridge first and wait a bit to ensure it's loaded | ||
| await this.registerMessageBridge(); | ||
|
|
||
| // Small delay to ensure message bridge is loaded and has injected UUIDs | ||
| await new Promise((resolve) => setTimeout(resolve, 50)); | ||
|
|
||
| // Then register the scripts that run in MAIN world | ||
| await this.registerPageProvider(); | ||
| await this.registerFlowScript(); | ||
| }; | ||
|
|
||
| private registerMessageBridge = async () => { | ||
| try { | ||
| await chrome.scripting.registerContentScripts([ | ||
| { | ||
| id: 'messageBridge', | ||
| matches: ['file://*/*', 'http://*/*', 'https://*/*'], | ||
| js: ['message-bridge.js'], | ||
| runAt: 'document_start', | ||
| world: 'ISOLATED', | ||
| allFrames: true, | ||
| }, | ||
| ]); | ||
| this.registeredScripts.add('messageBridge'); | ||
| consoleLog('Successfully registered message bridge content script'); | ||
| } catch (err) { | ||
| consoleError(`Failed to register message bridge content script: ${err}`); | ||
| } | ||
| }; | ||
|
|
||
| private registerPageProvider = async () => { | ||
| try { | ||
| await chrome.scripting.registerContentScripts([ | ||
| { | ||
| id: 'pageProvider', | ||
| matches: ['file://*/*', 'http://*/*', 'https://*/*'], | ||
| js: ['pageProvider.js'], | ||
| runAt: 'document_start', | ||
| world: 'MAIN', | ||
| allFrames: true, | ||
| }, | ||
| ]); | ||
| this.registeredScripts.add('pageProvider'); | ||
| consoleLog('Successfully registered pageProvider content script'); | ||
| } catch (err) { | ||
| consoleError(`Failed to register pageProvider content script: ${err}`); | ||
| } | ||
| }; | ||
|
|
||
| private registerFlowScript = async () => { | ||
| try { | ||
| await chrome.scripting.registerContentScripts([ | ||
| { | ||
| id: 'flowScript', | ||
| matches: ['file://*/*', 'http://*/*', 'https://*/*'], | ||
| js: ['script.js'], | ||
| runAt: 'document_start', | ||
| world: 'MAIN', | ||
| allFrames: true, | ||
| }, | ||
| ]); | ||
| this.registeredScripts.add('flowScript'); | ||
| consoleLog('Successfully registered flow script content script'); | ||
| } catch (err) { | ||
| consoleError(`Failed to register flow script content script: ${err}`); | ||
| } | ||
| }; | ||
|
|
||
| // Method to unregister scripts if needed | ||
| unregisterAllScripts = async () => { | ||
| try { | ||
| const registeredIds = Array.from(this.registeredScripts); | ||
| if (registeredIds.length > 0) { | ||
| await chrome.scripting.unregisterContentScripts({ | ||
| ids: registeredIds, | ||
| }); | ||
| this.registeredScripts.clear(); | ||
| consoleLog('Successfully unregistered all content scripts'); | ||
| } | ||
| } catch (err) { | ||
| consoleError(`Failed to unregister content scripts: ${err}`); | ||
| } | ||
| }; | ||
|
|
||
| // Method to check if scripts are registered | ||
| getRegisteredScripts = () => { | ||
| return Array.from(this.registeredScripts); | ||
| }; | ||
| } | ||
|
|
||
| export default new ContentScriptInjectionService(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,134 +1,10 @@ | ||
| import { nanoid } from 'nanoid'; | ||
| import { v4 as uuid } from 'uuid'; | ||
| // This content script is no longer used. | ||
| // We now inject scripts directly from the background service worker using chrome.scripting API. | ||
| // This file is kept as a stub to avoid build issues. | ||
|
|
||
| import { Message } from '@/shared/utils/messaging'; | ||
| import { consoleLog } from '@/shared/utils/console-log'; | ||
|
|
||
| const channelName = nanoid(); | ||
| consoleLog('Legacy content script loaded but not used.'); | ||
|
|
||
| const injectProviderScript = async (isDefaultWallet) => { | ||
| // Set local storage variables | ||
| await localStorage.setItem('frw:channelName', channelName); | ||
| await localStorage.setItem('frw:isDefaultWallet', isDefaultWallet); | ||
| await localStorage.setItem('frw:uuid', uuid()); | ||
|
|
||
| const container = document.head || document.documentElement; | ||
| const scriptElement = document.createElement('script'); | ||
| scriptElement.id = 'injectedScript'; | ||
| scriptElement.setAttribute('src', chrome.runtime.getURL('pageProvider.js')); | ||
|
|
||
| container.insertBefore(scriptElement, container.children[0]); | ||
|
|
||
| return scriptElement; | ||
| }; | ||
|
|
||
| injectProviderScript(true); // Initial call to check and inject if needed | ||
|
|
||
| const initListener = (channelName: string) => { | ||
| const { BroadcastChannelMessage, PortMessage } = Message; | ||
| const pm = new PortMessage().connect(); | ||
| const bcm = new BroadcastChannelMessage(channelName).listen((data) => pm.request(data)); | ||
|
|
||
| // background notification | ||
| pm.on('message', (data) => bcm.send('message', data)); | ||
|
|
||
| // pm.request({ | ||
| // type: EVENTS.UIToBackground, | ||
| // method: 'getScreen', | ||
| // params: { availHeight: screen.availHeight }, | ||
| // }); | ||
|
|
||
| document.addEventListener('beforeunload', () => { | ||
| bcm.dispose(); | ||
| pm.dispose(); | ||
| }); | ||
| }; | ||
|
|
||
| initListener(channelName); | ||
|
|
||
| // because the content script run at document start | ||
| setTimeout(() => { | ||
| document.body.setAttribute('data-channel-name', channelName); | ||
| }, 0); | ||
|
|
||
| /** | ||
| * Inject script | ||
| */ | ||
| // Listener for messages from window/FCL | ||
|
|
||
| function injectScript(file_path, tag) { | ||
| const node = document.getElementsByTagName(tag)[0]; | ||
| const script = document.createElement('script'); | ||
| script.setAttribute('type', 'text/javascript'); | ||
| script.setAttribute('src', file_path); | ||
| node.appendChild(script); | ||
| chrome.runtime.sendMessage({ type: 'LILICO:CS:LOADED' }); | ||
| } | ||
|
|
||
| injectScript(chrome.runtime.getURL('script.js'), 'body'); | ||
|
|
||
| // Listener for messages from window/FCL | ||
| window.addEventListener('message', function (event) { | ||
| chrome.runtime.sendMessage(event.data); | ||
| }); | ||
|
|
||
| // Listener for Custom Flow Transaction event from FCL send | ||
| // window.addEventListener('FLOW::TX', function (event) { | ||
| // // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // // @ts-ignore: Event detail | ||
| // chrome.runtime.sendMessage({type: 'FLOW::TX', ...event.detail}) | ||
| // }) | ||
|
|
||
| const extMessageHandler = (msg, _sender) => { | ||
| if (msg.type === 'FCL:VIEW:READY') { | ||
| if (window) { | ||
| window.postMessage(JSON.parse(JSON.stringify(msg || {})), '*'); | ||
| } | ||
| } | ||
|
|
||
| if (msg.f_type && msg.f_type === 'PollingResponse') { | ||
| if (window) { | ||
| window.postMessage(JSON.parse(JSON.stringify({ ...msg, type: 'FCL:VIEW:RESPONSE' })), '*'); | ||
| } | ||
| } | ||
|
|
||
| if (msg.data?.f_type && msg.data?.f_type === 'PreAuthzResponse') { | ||
| if (window) { | ||
| window.postMessage(JSON.parse(JSON.stringify({ ...msg, type: 'FCL:VIEW:RESPONSE' })), '*'); | ||
| } | ||
| } | ||
|
|
||
| if (msg.type === 'FCL:VIEW:CLOSE') { | ||
| if (window) { | ||
| window.postMessage(JSON.parse(JSON.stringify(msg || {})), '*'); | ||
| } | ||
| } | ||
|
|
||
| if (msg.type === 'FLOW::TX') { | ||
| if (window) { | ||
| window.postMessage(JSON.parse(JSON.stringify(msg || {})), '*'); | ||
| } | ||
| } | ||
|
|
||
| if (msg.type === 'LILICO:NETWORK') { | ||
| if (window) { | ||
| window.postMessage(JSON.parse(JSON.stringify(msg || {})), '*'); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
|
|
||
| /** | ||
| * Fired when a message is sent from either an extension process or another content script. | ||
| */ | ||
| chrome.runtime.onMessage.addListener(extMessageHandler); | ||
|
|
||
| const wakeup = function () { | ||
| setTimeout(function () { | ||
| chrome.runtime.sendMessage('ping', function () { | ||
| return false; | ||
| }); | ||
| wakeup(); | ||
| }, 2000); | ||
| }; | ||
| wakeup(); | ||
| // Export empty object to satisfy module requirements | ||
| export {}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.